Click here to Skip to main content
15,895,656 members
Articles / Web Development / ASP.NET

Web Service Authentication

Rate me:
Please Sign up or sign in to vote.
4.35/5 (41 votes)
25 Nov 2009CPOL3 min read 466.1K   8.3K   197  
A simple mechanism to authenticate users to a WebService
<%@ Page language="c#" Codebehind="TestAuth.aspx.cs" AutoEventWireup="false" Inherits="WebServiceAuthentication.TestAuth" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>TestAuth</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name=vs_defaultClientScript content="JavaScript">
		<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body MS_POSITIONING="GridLayout">

		<form id="Form1" method="post" runat="server">
			<asp:Label Runat=server ID=ServResponse BackColor=#ffcc00>WebServiceResponse</asp:Label>
			<hr>
			<asp:Label id="LabelUser" runat="server" Width="72px" Height="24px">UserName: </asp:Label>
			<asp:TextBox id="TextBoxUserName" runat="server"></asp:TextBox>
			<br>
			<asp:Label id="LabelPwd" runat="server" Width="72px" Height="24px">Password: </asp:Label>
			<asp:TextBox id="TextBoxPwd" runat="server"></asp:TextBox>
			<br>
			<asp:Label id="LabelToken" runat="server" Width="72px" Height="24px">Token: </asp:Label>
			<asp:TextBox id="TextBoxToken" runat="server" Width="300px"></asp:TextBox>
			<br>
			<br>
			<asp:Button id="ButtonAuth" runat="server" Text="TestAuthentication"></asp:Button>
			<br>
			<hr>
			The password to get authentication is: SeCrEt+"ServiceName".<br>
			I.D. if the "ServiceName" is "Test1" the password must be "SeCrEtTest1"<br>
			Please note that in this sample the password is case sensisitive, while the username is not.
			<br>
			<br>
			<asp:Label id=LabelSrv runat="server" Width="72px" Height="24px">Service: </asp:Label>
			<asp:TextBox id=TextBoxService runat="server">ServiceName</asp:TextBox>
			<br>
			<br>
			<asp:Button id="ButtonService" runat="server" Text="TestService"></asp:Button> Test Service Authorization using local clock
			<br>
			<br>
			<asp:Button id="ButtonGetToken" runat="server" Text="GetToken"></asp:Button> Service
			GetToken (the token you get here is valid during the current minute and the following)
			<br>
			<asp:Button id="ButtonUseToken" runat="server" Text="TestService"></asp:Button> Test Service Authorization using Token
		</form>

	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions