Ajax is an acronym for Asynchronous JavaScript and XML. It is a combination of different technologies, used for building rich and responsive user interfaces. Ajax is a popular technology that is used in many different ways on the World Wide Web. It has become a technology of choice for building fast and responsive user interfaces. Ajax provides support for partial page updates, rich and responsive user interfaces and reduced consumption of server resources.
ASP.NET Ajax also provides support for built in server side services of ASP.NET 2.0 like Authentication, Profiles, Membership, Roles, etc. Microsoft states, "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." Reference: https://www.asp.net/(S(ywiyuluxr3qb2dfva1z5lgeg))/learn/Ajax/tutorial-03-cs.aspx
This article discusses how you can work with the authentication and profile services using Ajax. The Profile object in ASP.NET can be used to store the user's profile information for later retrieval and usage.
Working with Authentication Service using Ajax
- Forms Authentication
- Windows Authentication
- Passport Authentication
The following code snippet illustrates the syntax for specifying authentication mode in the application's web.config file:
So, if you were to use Forms Authentication in your application, here's what you can specify in the application's web.config file:
Similarly, you can use the following configuration to specify that the application's authentication mode is Windows:
To implement Passport authentication in your application, you need to download and install the Passport SDK. Then, you can use configuration information in your application's web.config file similar to the following:
Note that you can also use your custom authentication mode for your application. To do that, you should turn off the default authentication using the following statement in your application's web.config file:
You can make use of the AuthenticationService class in ASP.NET Ajax to access authentication information using client side scripts. You have two methods in this class, namely, login and logout. While the former is used to verify the credentials of the user, the later can be used to clear the cookies and log the user out of the application. The following code snippet illustrates how you can enable authentication service using client side scripts:
You should also have Forms authentication enabled for your application to use authentication service using client side scripts.
The following code snippet illustrates how the Sys.Services.AuthenticationService.login() and Sys.Services.AuthenticationService.logout() methods can be used from client side scripts in your ASP.NET Ajax applications:
Working with the Profile Service
The Profile object in ASP.NET can be used to store the user's profile information for later retrieval and usage. Note that the authentication and profile services in ASP.NET Ajax are available as Sys.Services.AuthenticationService and Sys.Services.ProfileService classes respectively in the ASP.NET Ajax Extensions Library. Microsoft states, "The Microsoft ASP.NET 2.0 AJAX Extensions profile service enables you to use the ASP.NET profile application service in applications. You can access profile data by using ECMAScript (JavaScript) code that accesses a client representation of the profile." Reference: https://www.asp.net/AJAX/documentation/live/Tutorials/UsingProfileInformationTutorial.aspx
The following code snippet illustrates how you can enable Profile Service:
You can define your profile properties using the <profile> tag in your application's web.config file. Here is an example:
It is also possible to group your profile information using the <group> tag. Here is an example that illustrates how this can be done:
Suggested Readings
Here are a few links for further references on this topic:
https://www.asp.net/(S(ywiyuluxr3qb2dfva1z5lgeg))/learn/Ajax/tutorial-03-cs.aspx
https://msdn.microsoft.com/en-us/library/bb398816.aspx
https://www.asp.net/AJAX/documentation/live/Tutorials/UsingProfileInformationTutorial.aspx
https://msdn.microsoft.com/en-us/library/t745kdsh.aspx
Summary
The Authentication and Profile services are available as part of the ASP.NET Ajax Extensions Library. These are available as Sys.Services.AuthenticationService and Sys.Services.ProfileService classes in the ASP.NET Ajax Extensions Library. This article provided you a head start to the concepts related to Authentication and Profile Services and how they can be used from client side scripts using ASP.NET Ajax. Happy reading!