Software School Projects | Academic Students Projects | Source Codes | Tablets header
Please use our contact us form or send email to Support@srishtis.com.

Understanding ASP.NET AJAX Authentication and Profile Application Services
The Authentication service allows users to provide credentials in order to receive an authentication cookie, and is the gateway service to allow custom user profiles provided by ASP.NET. Use of the ASP.NET AJAX authentication service is compatible with standard ASP.NET Forms authentication, so applicationscurrently using Forms authentication (such as with the Login control) will not be broken by upgrading to the AJAX authentication service
Profiles and Authentication
The Microsoft ASP.NET Profiles and Authentication services are provided by the ASP.NET Forms Authentication system, and are standard components of ASP.NET. The ASP.NET AJAX Extensions provide script access to these services via script proxies, through a fairly straightforward model under the Sys.Services namespace of the client AJAX library. The Authentication service allows users to provide credentials in order to receive an authentication cookie, and is the gateway service to allow custom user profiles provided by ASP.NET. Use of the ASP.NET AJAX authentication service is compatible with standard ASP.NET Forms authentication, so applications currently using Forms authentication (such as with the Login control) will not be broken by upgrading to the AJAX authentication service. The Profile service allows the automatic integration and storage of user data based on membership as provided by the Authentication service. The stored data is specified by the web.config file, and the various profiling service providers handle the data management. As with the Authentication service, the AJAX Profile service is compatible with the standard ASP.NET profile service, so that pages currently incorporating features of the ASP.NET Profile service should not be broken by including AJAX support. Incorporating the ASP.NET Authentication and Profiling services themselves into an application is outside of the scope of this whitepaper. For more information on the topic, see the MSDN Library reference article “Managing Users by Using Membership” at http://msdn2.microsoft.com/en-us/library/tw292whz.aspx ASP.NET also includes a utility to automatically set up Membership with a SQL Server, which is the default authentication service provider for ASP.NET Membership. For more information, see the article ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)” at
http://msdn2.microsoft.com/en-us/library/ms229862(vs.80).aspx.
Using the ASP.NET AJAX Authentication Service.
The ASP.NET AJAX Authentication service must be enabled in the web.config file:
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" />
</webServices>
</scripting>
<system.web.extensions>
The Authentication service requires ASP.NET Forms authentication to be enabled and requires cookies to be enabled on the client browser (a script cannot enable a cookieless session since cookieless sessions require URL parameters). Once the AJAX authentication service is enabled and configured, client script can immediately take advantage of the Sys.Services.AuthenticationService object. Primarily, client script will want to take advantage of the login method and isLoggedIn property. Several properties exist to provide defaults for the login method, which can accept a large number of parameters.
Sys.Services.AuthenticationService members
login method:
The login() method begins a request to authenticate the user’s credentials. This method is asynchronous and does not block execution.
logout method:
The logout() method removes the credentials cookie and logs out the current user from the web application.
Code Sample: Logging into the Authentication Service
<@ Page Language="C#" AutoEventWireup="True" CodeFile="Default.aspx.csx" Inherits="_Default" >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Example</title>
<script type="text/javascript">
function Login()
{
var userTextbox = $get("txtUser");
var passTextbox = $get("txtPassword");
Sys.Services.AuthenticationService.login(userTextbox.value,passTextbox.value, false, null, null, LoginServiceCompleted, LoginServiceFailed, "Context Info");
}
function Logout()
{
Sys.Services.AuthenticationService.logout(null,LogoutServiceCompleted,LoginServiceFailed ,"Context Info");
}
function LoginServiceFailed(error, userContext, methodName)
{
alert('There was an error with the authentication service:\n\n' + error);
}
function LoginServiceCompleted(validCredentials, userContext, methodName)
{
if (validCredentials)
{
alert('Great! You successfully logged in.');
}
else
{
alert('Oops! You gave us bad credentials!');
}
}
function LogoutServiceCompleted(result, userContext, methodName)
{
alert('You have been logged out from the web site.');
}
</script>
</head>

<body>
<form id="form1" runat="server">
<asp:ScriptManagerID="ScriptManager1" runat="server" EnableScriptLocalization="true">
</asp:ScriptManager>
<div>
<asp:TextBox ID="txtUser" runat="Server"></asp:TextBox><br/>
<br/>
<asp:TextBox ID="txtPassword" runat="Server" TextMode="Password"><
<br/>
<asp:Button Text="Log in" ID="btnLogin" runat="server" OnClientClick="Login(); return false;"/>
</div>
</form>
</body>
</html>
Accessing ASP.NET Profiling Data via AJAX
The ASP.NET profiling service is also exposed through the ASP.NET AJAX Extensions. Since the ASP.NET profiling service provides a rich, granular API by which to store and retrieve user data, this can be an excellent productivity tool.
The profile service must be enabled in web.config; it is not by default. To do so, ensure that the profileService child element has enabled=”true” specified in web.config, and that you have specified which properties can be read or written as follows:
<system.web.extensions>
<scripting>
<webServices>
<profileService enabled="true" readAccessProperties=”Name,Address,BackgroundColor” writeAccessProperties=”BackgroundColor”>
</webServices>
</scripting>
</system.web.extensions>
The profile service must also be configured. Although configuration of the profiling service is outside of the scope of this whitepaper, it is worthwhile to note that groups as defined in profile configuration settings will be accessible as sub-properties of the group name. For example, with the following profile section specified:
<profile enabled="true">
<properties>
<add name="Name" type="System.String" />
<group name="Address">
<add name="Line1" type="System.String" />
<add name="Line2" type="System.String" />
<add name="City" type="System.String" />
<add name="State" type="System.String" />
<add name="BackgroundColor" type="System.Drawing.Color" />
</properties>
</profile>
Client script would be able to access Name, Address.Line1, Address.Line2, Address.City, Address.State, Address.Zip, and BackgroundColor as properties of the properties field of the ProfileService class. Once the AJAX Profiling Service is configured, it will be immediately available in pages; however, it will have to be loaded once before use.
Client script would be able to access Name, Address.Line1, Address.Line2, Address.City, Address.State, Address.Zip, and BackgroundColor as properties of the properties field of the ProfileService class. Once the AJAX Profiling Service is configured, it will be immediately available in pages; however, it will have to be loaded once before use.
Sys.Services.ProfileService members
properties field:
The properties field exposes all configured profile data as child properties that can be referenced by the dot-operator-name convention. Properties that are children of property groups are referred to as GroupName.PropertyName. In the example profile configuration presented above, to get the state of the user, you could use the following identifier:
Sys.Services.ProfileService.properties.Address.State
load method:
Loads a selected list or all properties from the server.
save method:
The save() method saves the specified property list (or all properties) to the user’s ASP.NET profile.
Code sample: Loading profile data at page load
The following code will check to see whether a user is authenticated, and if so, will load the user’s preferred background color as the page’s.
function Page_Load()
{
if (Sys.Services.AuthenticationService.get_isLoggedIn())
{
Sys.Services.ProfileService.load();
}
}
function ProfileLoaded(numPropsLoaded, userContext, methodName)
{
document.documentElement.style.backgroundColor = Sys.Services.ProfileService.properties.BackgroundColor;
}
Job or extra money for students

Search Engine Rank of your blog or websites