Use role-based identity forms validation in asp.net (2) __.net

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.