One-step implementation of Asp.net Forms single-point logon in most cases

Source: Internet
Author: User

 

The implementation of Asp.net single-point logon, after Google, you will find that it is complicated and frustrating.

In fact, most of the requirements do not need to be so complicated. Requirements of most people (including me): There is only one site, and multiple applications require a unified logon interface for multiple applications to use, and there is only one server (small company ):. You do not need to log on to each application once.

 

 

You only need one step to modify Web. config:

 

<Authentication mode = "Forms">

<Forms name = "FormsAuthCookie" path = "/" timeout = "2880"/>

</Authentication>

<MachineKey validationKey = "AutoGenerate" decryptionKey = "AutoGenerate" validation = "SHA1"/>

That's easy!

 

 

 

Note that the name attribute of forms must be the same and machineKey must be configured as above. If it is a machine, the keys generated for encryption and decryption of cookies are the same, that is why we emphasize that there is only one machine. If it is on different servers, you must manually set validationKey and decryptionKey to the same value. The default machinekey is as follows: validationKey = "AutoGenerate, IsolateApps" decryptionKey = "AutoGenerate, IsolateApps ". IsolateApps make the machinekey of different applications different, thus preventing cookie tickets from being shared.

 

 

 

 

 

 

The following content is a supplement:

 

Asp.net Forms authentication process overview:

 

1. user login verification code:

 

If (ValidateUser (userName, passWord) // Verify validity

{

System. Web. Security. FormsAuthentication. SetAuthCookie (userName, rememberMe); // set the encryption cookie that is saved to the client, which must be set in machinekey.

// If you need to access more data in the cookie, use FormsAuthenticationTicket to encrypt the ticket with FormsAuthentication.

 

// Redirect...

}

 

 

2. You need to log on to the user to access:

 

 

If (Request. IsAuthenticated) // The Asp.net Forms authentication module saves us a lot of trouble. The process is probably to decrypt the cookie sent from the client. if it is legal, it will...

{

If (User. IsInRole ("admins") // both User and Role are ready. if you use membership

{

// Administrator role...

}

Else

{

//...

}

}

Else

{

// Go to login. aspx

}

Author slmk

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.