Second-level domain name Cookie Problems and Solutions

Source: Internet
Author: User

After using the second-level domain name in the Blog Park today, it is found that even if the user has logged on, but the second-level domain name Blog page shows that the user has not logged on (in the form of a comment, you need to enter a verification code, the favorites function cannot be used normally). After you log on again, you still need to log on to other second-level domain names. In the code, I used Request. IsAuthenticated to determine whether the current Request was verified. Previously, it was normal to use www.cnblogs.com domain names. It seems that the domain names are different. For Form verification, the verification is carried out through the cookie and the Request is executed. when IsAuthenticated, the client will request the corresponding Cookie. The Cookie name is in the web. as specified in config, for example, blog garden web. settings in config:

<Authentication mode = "Forms">
<Forms name = ". DottextCookie" loginUrl = "login. aspx" protection = "All" timeout = "480" path = "/"/>
</Authentication>

That is to say, the Request is being executed. when IsAuthenticated, code like this will be executed, HttpCookie cookie = Request. cookies [". dottextCookie "]; we know that cookies are associated with Domain names, and HttpCookie has a Domain attribute. The problem encountered in the blog garden is that the second-level domain name cannot access the cookie of the primary domain name. When logging on, the blog garden program passes FormsAuthentication. setAuthCookie sets the Cookie, and the login code is executed under the domain name www.cnblogs.com. The cookie domain name is set to www.cnblogs.com by default, and we cannot access this cookie under the second-level domain name, how can this problem be solved? Can the cookie domain be set to be valid for all second-level domain names? After searching for it in Google, I finally found an article (Tips On Using SubDomain). I could have set the domain associated with the cookie". Domain. ext", The setting of the blog is .cnblogs.com. In this way, after FormsAuthentication. SetAuthCookie, add this code to solve the problem:

HttpCookie cookie = Request. Cookies [". DottextCookie"];
If (cookie! = Null)
{
Cookie. Domain = ".cnblogs.com ";
Response. Cookies. Add (cookie );
}

Note:
1. If you still need to log on to the second-level domain name again, delete the cookie file in your computer. The path is in C: \ Documents and Settings \ User Name \ 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 problems related to the second-level domain name, please contact me in time.
3. if you encounter a "Runtime Error" when visiting the blog, it is because the dll file has just been updated. You can re-open IE in 1 or 2 minutes.
4. Now the second-level domain name is fully enabled.

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.