Verification Method
We can use one of the following four methods to write and redirect tickets. In fact, the first three methods are only encapsulation of the first 4th methods. 1 and 4 are recommended. Note that cookieless = "useuri" is not supported in the last three methods ".
// 1. Use the default authentication ticket
Formsauthentication. redirectfromloginpage ("username", true );
// 2. Use the default authentication ticket
Formsauthentication. setauthcookie ("username", false );
Response. Redirect (formsauthentication. getredirecturl ("username", false ));
// 3. Use the default authentication ticket
Response. Cookies. Add (formsauthentication. getauthcookie ("username", false ));
Response. Redirect (formsauthentication. getredirecturl ("username", false ));
// 4. Use a custom authentication ticket
Formsauthenticationticket ticket = new formsauthenticationticket (1, "username", datetime. Now, datetime. Now. addminutes (10), 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 creden stored in the application configuration file. This method can only verify the user name and password information stored in Web. config. In most cases, we will replace it with our own verification method.
Decrypt
Decrypts the encrypted string obtained from the cookie and creates the formsauthenticationticket object.
Encrypt
Encrypted formsauthenticationticket. The encrypted string is returned.
Getredirecturl
Returns the original request URL that causes redirection to the logon page. The getredirecturl method returns the URL specified by the returnurl variable name in the query string. For example, in the URL http://www.contoso.com/login.aspx? In returnurl = caller. aspx, The getredirecturl method returns caller. aspx. If the returnurl variable does not exist, the getredirecturl method returns the URL in the defaulturl attribute.
Redirectfromloginpage
Redirects authenticated users back to the original requested URL or defaurl URL.
Redirecttologinpage
Redirects the browser to the logon URL.
Renewticketifold
Conditional update of the issuance date and time, expiration date and time of formsauthenticationticket. Note that this method only returns the updated formsauthenticationticket object and does not write cookies.
Getauthcookie
Create an authentication cookie for the given user name and do not add it to the cookie set or URL of the response.
Setauthcookie
Create an authentication ticket for the provided user name and add it to the cookie set or URL of the response.
Signout
Delete the forms authentication ticket from the browser.
Ticket Custom Data Application
When using a custom ticket, we can add a userdata parameter. Using this parameter can bring unexpected benefits, such as storing the user's VIP level number and the permissions/role set. Of course, the length of cookie and URL parameters is limited, and the custom data cannot be too long.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/Python/archive/2008/11/11/3277357.aspx