Two-level domain name Cookie Problem Solving Method _ practical skills

Source: Internet
Author: User
In the code, I am through the request.isauthenticated to determine whether the current request is verified, previously all used www.cnblogs.com domain name is normal, it seems that the domain name is different caused. For form validation, authentication is done through cookies, and when the request.isauthenticated is executed, the client's corresponding cookie is requested, The cookie name is specified in the web.config, such as the setting in the blog Garden web.config:
Copy Code code as follows:

<authentication mode= "Forms" >
<forms name= ". Dottextcookie "loginurl=" Login.aspx "protection=" All "timeout=" "path="/"/>"
</authentication>

That is to say, when executing request.isauthenticated, code like this is executed, httpcookie cookie = request.cookies[. Dottextcookie "]; we know that cookies are associated with a domain name, and HttpCookie has the domain attribute. Blog Park encountered a problem is that the two domain name can not access the main domain of cookies, log on, the program through the Formsauthentication.setauthcookie blog set Cookies, And the login code is executed under the www.cnblogs.com domain name, the cookie domain name is set to Www.cnblogs.com, and we can not access this cookie under the level two domain name, how to solve this problem? Can the domain of the cookie be set to be valid for all level two domains? Looking for it in Google, and finally finding an article (Tips on Using subdomain), you can set the domain that the cookie is associated with to ". Domain.ext", The setting of the blog Park is. cnblogs.com. In this way, after I formsauthentication.setauthcookie, adding such code will solve the problem:
C#
Copy Code code as follows:

HttpCookie cookie = request.cookies[". Dottextcookie "];
if (cookie!=null)
{
Cookie. Domain = ". Cnblogs.com";
RESPONSE.COOKIES.ADD (cookie);
}
Note:
1, if you still encounter access to the two-level domain name to be logged on again, please delete the corresponding cookie file on your computer, the path in C:\Documents and Settings\ username \cookies and C:\Documents and Settings\ User name \local Settings\Temporary Internet files, the file format is: User name @www.cnblogs.com, and then log on again.
2, if you find other related to the level of two domain name issues, please contact me in time.
3, if you visit the blog park, the "Runtime error" error, that is because just updated the DLL file, you have 1, 2 minutes to reopen IE access on the line.
4, now has fully enabled the level two domain name.

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.