Asp.net authentication and authorization

Source: Internet
Author: User

Asp.net authentication and authorization

Identity Authentication is the process of determining the user's identity. after the user passes authentication, the developer can determine whether the user has the right to continue the operation. if identity authentication is not performed, entity authorization cannot be performed.
Authorization is used to determine whether the authenticated user has the right to access the application.ProgramA part, a point, or only a specific dataset provided by the application can be accessed. After the user and group are authenticated and authorized, the site can be customized based on the user type or configuration.
Asp.net authentication method:
1. Basic Authentication
2. Digest Authentication
3. Form Authentication
4. Passport Authentication
5. Integrated windows Verification
You can also develop your own verification methods.

<System. Web>
<Authentication mode = "forms">
<Forms loginurl = "~ /Account/login. aspx "timeout =" 2880 "/>
</Authentication>
...
</System. Web>

Available options
<Authentication mode = "Windows | forms | passport | none">

Forms: requests that fail verification are redirected to an HTML form using an HTTP client. You must provide logon information and submit the form.
If the application verifies the request, the system sends a form that contains a certificate or key for re-obtaining the identity.

Protected void application_authenticaterequest (Object sender, eventargs e) {httpapplication APP = (httpapplication) sender; httpcontext context = app. context; // obtain the httpcontext object if (context. request. isauthenticated) // a verified general user can perform role verification {formsidentity id = (formsidentity) context. user. identity; // The current user ID formsauthenticationticket ticket = ID. ticket; // get the ID card string [] roles = ticket. userdata. split (','); // convert the role data into a string array to obtain the context of the role. user = new system. security. principal. genericprincipal (ID, roles); // regenerate the user with role information} string userid = "XX"; string Pa = "123"; string roles = "Administrator "; // obtain user role data from other locations. formsauthenticationticket ticket = new formsauthenticationticket (1, userid, datetime. now, datetime. now. addminutes (30), true, roles); // create an identity authentication ticket object string hashticket = formsauthentication. encrypt (ticket); // The encrypted serialization validation ticket is a string httpcookie usercookie = new httpcookie (formsauthentication. formscookiename, hashticket); // generate cookie context. response. cookies. add (usercookie); // Bill write cookie response. redirect ("info. aspx ");

 
If (this. username. TEXT = "XX" & this. password. TEXT = "00") {formsauthentication. redirectfromloginpage (this. username. text, true);} else this. failuretext. TEXT = "incorrect user name or password ";

 

Related Article

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.