V J

Sunday, May 01, 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,

0 Comments:

Post a Comment

<< Home