User Authentication Using ASP.NET Membership Authentication Service and JQuery

Form Authentication provides a great feature to make AJAX calls to membership. This provide added benefit because you can use jQuery and CSS to build nice client side UI and still be able to leverage power of membership providers for user authentications and validations. Today we will implement User Authentication using JQuery and Membership Service (provided with Microsoft AJAX) to AJAXify our login page. Here is a quick look of final result:


So, in order to call Membership Authentication Web Service, we need to add some markup in Web.Config file:




<authenticationService enabled="true" requireSSL="false"/>




Note: I am using this in my local machine so I do not need SSL but if you are implementing this for your production website and you have SSL certificate installed in your production server for HTTPS support, I would recommend you setting requireSSL to True.

Second, we need to add script manager instance to our page so we can include Microsoft AJAX library on the page.

<asp:ScriptManager ID="ScriptManager1" runat="server">


Once this is added, after this code is very straight:

<html xmlns="">

<head runat="server">


<script type="text/javascript" src=""></script>

<style type="text/css">






border:solid 2px lightgray;


















<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">


<div id="Login">


Username: <input id="_txtUsername" type="text" /><br />

Password : <input id="_txtPassword" type="password" /><br />

<input id="Button1" type="button" value="Login" /><br />

<span id="result"></span>


<script type="text/javascript">

$(document).ready(function() {

var Username = "";

var Password = "";

$('#Button1').click(function() {

Username = $('#_txtUsername').val();

Password = $('#_txtPassword').val();


// Syntax for following is Sys.Services.AuthenticationService.login(userName, password, isPersistent, customInfo, redirectUrl, loginCompletedCallback, failedCallback, userContext);



Sys.Services.AuthenticationService.login(Username, Password, false, null, 'LoginCheck.aspx', CompleteCallBack, null, Username);




function CompleteCallBack(validUser, context, methodName) {

if (validUser == true) {

$('#result').text('Welcome , ' + context);


else {

$('#result').text('Login Failed for username, ' + context).addClass('error');











That's it now in order to check whether we have successfully authenticated user or not I am redirecting user to Login Check page where page is going to print authenticated user's username using Login name server control of once user is authenticated):

Tags: , , ,

AJAX | ASP.NET | jQuery | Membership