[Goto] 2 small issues that are easily overlooked in ASP. Cookie garbled access exception and IFRAME bullet box login Jump

Source: Internet
Author: User
Tags goto urlencode

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

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.