User-719153870 posted
Hi jsshivalik,
Forms Authentication Ticket is used to retain the personal information of the current user so that the application can distinguish the identity of the current user.
If you want to know more details about FormsAuthenticationTicket, you can refer to below link:
https://docs.microsoft.com/en-us/dotnet/api/system.web.security.formsauthenticationticket?view=netframework-4.8
Or if you are confused about the constructor of your FormsAuthenticationTicket, please refer to below link:
https://docs.microsoft.com/en-us/dotnet/api/system.web.security.formsauthenticationticket.-ctor?view=netframework-4.8#System_Web_Security_FormsAuthenticationTicket__ctor_System_Int32_System_String_System_DateTime_System_DateTime_System_Boolean_System_String_System_String_
As for the example you provided, you can refer to the notes I added below:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(30), isPersistent, userData, FormsAuthentication.FormsCookiePath);//Build a ticket with some user related information.
string encTicket = FormsAuthentication.Encrypt(ticket);//Encrypt the ticket.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));//Generate corresponding cookie.
Response.Redirect("Default.aspx");
Best Regard,
Yang Shen