Web Authentication Mode--form Authentication

Source: Internet
Author: User
Tags ticket

Form validation is not an HTTP standard, but a validation method provided under the Microsoft ASP. NET Web framework. The approximate process is as follows:

In the process, ASP. NET Framework provides the following support classes: ( FormsAuthentication, FormsAuthenticationModule)

In the third step of the flowchart above, we verify the user name password.

-You can create a Formauthenticationticket object to deposit user data into it.

-Then call the tool method of the Formauthentication class encrypt get the ticket string that has been added

-Writes the ticket string to a cookie named Formauthentication.formcookiename

-In subsequent requests, the browser will bring the cookie.

In the fourth step of the flowchart above, Formauthenticationmodule will intercept the request in the IIS authenticate event

-Verify (decrypt) The value of the cookie that is carried in the request named Formauthentication.formcookiename

-If authentication is passed, create a Genericprinciple object with the user information that is carried in the cookie and save it in the HttpContext of the current request and set the request to authenticated

-If the validation does not pass, or if no corresponding cookie is found, return 401 to the browser

See Formauthenticationmodule source code.

To open the form Authenticate authentication method in an ASP. NET application, simply add the following configuration to the <system.web> configuration section:

<mode= "Forms">      <loginurl= "Login"  name= "JW." Auth "/>//here defines the login URL and the name of the cookie </authentication>

A link in the flowchart above is not described in steps 1 and 4 to verify that the user has permission to access the page. Asp. NET can deny users who are not logged in by configuring the following configuration to the <system.web> configuration section:

< Authorization >      <  users= "?" />//here to deny all login users, here can also add <allow> nodes allow specific users, role to launch a specific HTTP method, but not with the URL of the map feel a little bit of a chicken. You can implement your own validation logic in a real project </authorization>

Asp. NET Framework is authorized by configuration in the authorization request link of IIS by UrlAuthorizationModule this HTTP module in the above class diagram. An unauthorized request returns a 401 error.

See UrlAuthorizationModule Source code

Summary:

Form authentication is a built-in validation method in the ASP. NET Framework. It uses a cookie as a way to verify the ticket, and the cookie is valid by default in the session.

Test code See Https://github.com/lbwxly/Authentication

Web Authentication Mode--form Authentication

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.