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.