Validation method
We can use one of the following 4 methods for ticket writing and redirection operations, but the first 3 are simply encapsulation of the 4th method. Recommended use of 1, 4. Note that the following three methods do not support cookieless= "UseUri".
1. Use default authentication ticket
FormsAuthentication.RedirectFromLoginPage ("username", true);
2. Use default authentication ticket
Formsauthentication.setauthcookie ("username", false);
Response.Redirect (Formsauthentication.getredirecturl ("username", false));
3. Use default authentication ticket
RESPONSE.COOKIES.ADD (Formsauthentication.getauthcookie ("username", false));
Response.Redirect (Formsauthentication.getredirecturl ("username", false));
4. Using a custom authentication ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (1, "username", DateTime.Now, DateTime.Now.AddMinutes (a), false, NULL);
RESPONSE.COOKIES.ADD (New HttpCookie (Formsauthentication.formscookiename, Formsauthentication.encrypt (ticket)));
Response.Redirect (Formsauthentication.getredirecturl ("username", false));
FormsAuthentication
Authenticate
Verify the user name and password against the credentials stored in the application configuration file. This method can only verify the username and password information stored in the web.config, and most of the time we will replace it with our own authentication method.
Decrypt
Decrypts the encrypted string obtained from the Cookie, creating the FormsAuthenticationTicket object.
Encrypt
Encrypts the FormsAuthenticationTicket, returning the encrypted string.
Getredirecturl
Returns the original request URL that caused the redirection to the login page. The Getredirecturl method returns the URL specified in the query string using the ReturnUrl variable name. For example, in the URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx, the Getredirecturl method returns the return caller.aspx. If the ReturnUrl variable does not exist, the Getredirecturl method returns the URL in the Defaulturl property.
RedirectFromLoginPage
REDIRECT the authenticated user back to the originally requested URL or Defaulturl.
Redirecttologinpage
Redirects the browser to the login URL.
Renewticketifold
Conditionally update the issue date and time of the FormsAuthenticationTicket and the expiration date and time. Note that this method simply returns the updated FormsAuthenticationTicket object and does not write to the cookie.
Getauthcookie
Creates an authentication cookie for the given user name and is not added to the response's cookie collection or URL.
SetAuthCookie
Creates an authentication ticket for the provided user name and adds it to the Cookie collection or URL of the response.
SignOut
Deletes the FORMS authentication ticket from the browser.
Ticket Customization Data Application
When using a custom ticket, we can add a userData parameter. Good use of this parameter can also bring some unexpected benefits, such as the storage user VIP level number, the permissions/role set. Of course the Cookie and URL parameters are limited in length, and this custom data cannot be too long.