Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Using FormsAuthentication the correct way

$
0
0

I am developing a site which uses FormsAuthentication. I am not using the built-in asp.net Membership feature. The <authentication mode is set to forms> in the web.config file. Roles are also defined in the Global.asax file. On the login page, this is code I use:

if (user is authenticated)
{
     FormAuthenticationTicket t = New FormsAuthenticationTicket (...);
     string hash                = FormAuthentication.Encrypt (t);
     HttpCookie myCookie        = new HttpCookie (FormsAuthentication.FormsCookieName, hash);
     Response.Cookies.Add (myCookie);

     string url = Request.QueryString ["returnURL"];
     Response.Redirect (url);
}
else
{
     // display error message
}

I just want to know if the above code is the correct way to use FormAuthentication. Please correct me if I am mistaken. Thanks...


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>