ASP. NET Forms authentication implementing subdomain sharing and login Defects

Source: Internet
Author: User
Tags exit in subdomain subdomain name

1. What is single sign-on
Single Sign-on is a unified logon method among multiple web applications. Once a web application is logged on

You do not need to log on again in sequence. All associated web applications exit in one place.

 

Ii. Defects in subdomain sharing login can be achieved through ASP. NET forms Authentication Mode

To use the ASP. Net form Authentication Mode to share the login status of different subdomains in the same primary domain, you need to configure the following

Configure web. config

 

1. Change the Asp.net Authentication mode to the forms authentication mode. The domain must be the domain name corresponding to your application, for example, .test.cn.

<Authentication mode = "forms">
<Forms name = ". aspnetform" Domain = ".test.cn" loginurl = "/login. aspx" defaulturl = "/default. aspx"

Protection = "all" timeout = "30" Path = "/" requiressl = "false" slidingexpiration = "true"

Enablecrossappredirects = "false" cookieless = "usedeviceprofile"/>
</Authentication>


2. Configure the encryption and decryption method for the ticket information stored in the cookie

 

<Machinekey

Validationkey = "success

E4e5eda-51e17c91830993445d0ea5708babbd "decryptionkey =" 5d37ddb652b86956 "validation =" sha1 "/>

Remarks: generate a machinekey URL
Http://www.aspnetresources.com/tools/keycreator.aspx

Log in to create a ticket

1. On the application login page (login. aspx), enter the user name, password, and verification pass. Then, create an encrypted authentication ticket and store it in the cookie.

// Create a verification ticket
Formsauthenticationticket ticket
= New formsauthenticationticket (1, name, datetime. Now,
Datetime. Now. adddays (1D), false,
Httpcontext. Current. Request. userhostaddress
);
String authticket = formsauthentication. Encrypt (ticket );
Httpcookie cookie = new httpcookie (formsauthentication. formscookiename, authticket );
Cookie. Domain = configurationmanager. receivettings ["ssodomain"];
Httpcontext. Current. response. Cookies. Add (cookie );

2. After logging in, enter the authorized page and obtain the ID user. Identity. name after the verification is passed;

 

If (! User. Identity. isauthenticated)
{
// Not logged on
Response. Redirect ("/login. aspx ");
}
String name = user. Identity. Name;

 

3. log out of the page, clear user information, and destroy tickets

Httpcontext. Current. session. Clear ();
Formsauthentication. signout ();

Iii. Defects in Forms authentication implementing subdomain sharing Login

As described above, multiple subdomains under the same primary domain name can share the logon status, but the primary domain name is limited. When the primary domain name is 1 letter, domain names suffixed with 2 letters cannot pass authentication. For example, a.cn domain names and a.jp domain names cannot achieve shared sub-domain names login, while other domain names can achieve, such as a.test.com, a.sina.cn and so on. You can also test it by modifying the hosts file. If you know how to solve this problem, please advise. Thank you !! The demo program is attached. Please advise!

PS: Because my company's domain name is p.cn, I want to use the form Authentication Mode to achieve subdomain name sharing login status, but it cannot be used !~~!! Khan, I don't know if this is a Microsoft Bug.

 

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.