This article transferred from: http://www.cnblogs.com/outtamyhead/p/3642729.html
This address:http://www.cnblogs.com/outtamyhead/p/3642729.html, reprint need to retain this address.
There have been two very small, but often troublesome, problems in my MVC project, and I'll take the time to record it here at noon.
A: In the local debugging environment can read the cookie normally, but published to IIS can not read, report null pointer exception.
Second: Due to the use of the IFRAME framework, but also added the session timeout to re-login restrictions, but the login page will appear in the center, very awkward.
For the first question, the main problem arises when the cookie is not encoded and decoded. In the absence of these two codes, the value reading the cookie will report a null pointer exception. So, it would be nice to add these two yards when using cookies.
New HttpCookie ("username", Httputility.urlencode (username));
String cookie_username = Httputility.urldecode (filterContext.RequestContext.HttpContext.Request.Cookies ["username"]. Value);
So here we suggest that, in order to avoid the occurrence of unreasonable things, or not lazy. Now let's take a look at MSDN's explanations for UrlEncode and UrlDecode.
It is important to note that UrlEncode and UrlDecode should appear in pairs so that there is no problem.
For more information, please see the additional article in the garden here or here, two articles like, but do not know who is the original, O (╯-╰) o
For the second problem, the relative is simple, just need to make a judgment on the login page. The specific code is as follows:
<script language= "javascript" type= "Text/javascript" > if (window! = top) top.location.href = location.href;</script>
[Goto] 2 small issues that are easily overlooked in ASP. Cookie garbled access exception and IFRAME bullet box login Jump