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");
}  

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments