Last post Jun 24, 2019 05:09 AM by Yang Shen
Jun 22, 2019 05:09 PM|jsshivalik|LINK
How the below code works
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(30), isPersistent, userData, FormsAuthentication.FormsCookiePath);
string encTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
Jun 22, 2019 06:58 PM|PatriceSc|LINK
Do you mean what it does or how it internally works ? In short information for the user which just logged is encrypted and sent back to the browser which will send that back with each http query to your site allowing to know which authenticated user
is sending this http request.
Try https://support.microsoft.com/en-us/help/910443/understanding-the-forms-authentication-ticket-and-cookie for details. If looking for
some internal detail, most of .NET code is now publicly available for example at https://referencesource.microsoft.com/ for .NET 4.x
Or if you have some issue with that just tell directly about it.
Jun 24, 2019 05:09 AM|Yang Shen|LINK
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:
Or if you are confused about the constructor of your FormsAuthenticationTicket, please refer to below link:
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.