Posted by: wajahatabbas | May 1, 2005

ASP.Net — Forms Authentication Makes your life more simple than the previous age of SESSIONS

Well its so easy to have form based authentication in ASP.Net instead of having sessions in your web app.

What you have to do is easy , follow the steps below,

where you get the login name and password and as you authenticate the user just put a line after that

____________________________________

System.Web.Security.FormsAuthentication.SetAuthCookie(txtLoginID.Text, False)

____________________________________

Now this ID will keep stored in the Forms (like the same manner we store values in session), you can always access the value if required, like as following,

____________________________________
context.User.Identity.Name
____________________________________

And to check the user has been authenitcated on different pages just paste the following code.

____________________________________
If Not Request.IsAuthenticated Then
Response.Redirect(“Login.aspx”, False)
End If

____________________________________

To log out the user, just paste the following code,

____________________________________
System.Web.Security.FormsAuthentication.SignOut()
Response.Redirect(“Login.aspx”, False)
____________________________________

I hope you will find it quite easy to maintain the session using Forms Authentication instead of using Sessions.

Enjoy .Netting,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: