formsauthenticationticket

formsauthenticationticket

Here Andrew Zhu, has explained how to generate  net formsauthentication asp.net.

Assume you are using FormsAuthentication.RedirectFromLoginPage() to direct user's request after loging in.

Now, you want the request to be redirected to different pages up to different users. you may need to write you own code to achieve this:

Validate user using Membersip

if (Membership.ValidateUser(TextBox1.Text, TextBox2.Text)) 
 
  {
   // Generate FormsAuthentication ticket
            FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(TextBox1.Text, true, 10);
   // FormsAuthntication encrypt ticket
            string cookiestring = FormsAuthentication.Encrypt(tkt);
   //Create cookie FormsAuthentication Cookie
            HttpCookie httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestring);
   // Give cookie FormsAuthnetication Cookie path
            httpCookie.Path = FormsAuthentication.FormsCookiePath;
   // Send cookie in response
            Response.Cookies.Add(httpCookie);

            //then, redirect whatever page you want here

            Response.Redirect("url");
}  

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.