Original: IE10, IE11 user-agent caused the ASP to write cookie problem
Have you ever experienced the use of a Web site or management system that involves cookie manipulation, IE 6, 7, 8, 9 run well, only to the IE10, 11 these high-version browser is not? Well, the problem is that the farmer has met 2 times in 2 consecutive days. So, let's take a look at the causes and consequences of this problem.
First of all, this 2 times the use of the scene, one is in a page, the first to save the cookie, and then storage records related data, but published to the production environment, the warehousing operation did not occur; Later, the problem card is found by printing the log here:
if (Request.Browser.Cookies)
That is, in the context of the client is IE10, this returns false! Nani, IE10 does not support cookies under default configuration? Microsoft, you play with me.
The second time is the upgrade test of a certain city, in the IE10 environment, since the service website Login failed; This is a strange question, because it has been upgraded to several cities, IE10 use is normal. This greatly aroused the interest of the Yards farmers, which led to this article.
After describing the scene, we analyze and analyze it. Although the intuition tells the code farmer, may be the cookie reads or writes the question, but after all the intuition this thing is not reliable, we still have to use the fact and the evidence to speak. International practice, first grab an HTTP packet to see:
is the HTTP response header returned by the server when the login failure is IE10, the HTTP response header returned by the server when the other browser is logged in normally, notice the red box callout part;
The direct cause of the problem is clear: when the server responds to the request, there is no postback Set-cookie header, and the client browser cannot write the Cookie without the header. Therefore, the self-service Web site based on form authentication (which is credited to the cookie) will not be able to log in.
At this point, you may find it strange, why only IE10, IE11 will be so, other IE browser running the completed? Well, to satisfy your curiosity, we continue to analyze.
If your machine is loaded. NET of the Framework, open this directory C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\Browsers. Under Popular Science, the. browser files in the folder are globally accessed to identify the browser that made the request and identify the features that these browsers have. If you want to make custom modifications (such as for a specific mobile device), simply copy the corresponding. browser file to the application's \app_browsers folder to modify it. First open the IE.browser file with Notepad,
Note the regular expression labeled red in the figure, and then take a look at Microsoft's published IE10 user-agent: mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; trident/6.0), the MSIE version number is now 2 digits (10) from the previous 1-digit number (5-9), and it is obvious that the above is not matched. So, because IE10 's user-agent could not be correctly identified, ASP. NET sees it as an unknown browser that does not support cookies, resulting in a series of cookie-related problems.
The root of the problem is finally known, so how to solve it?
In fact, this issue has been officially confirmed by Microsoft, is a IE10 bug, in fact, can also be considered as ASP. NET 2.0, 3.5, 4.0 bug, because these versions are not recognized IE10 user-agent. Microsoft has specifically released hotfix to fix this problem:
- Kb2600088:hotfix for ASP. NET in the Microsoft.NET Framework 4.0
- Kb2608565:hotfix applies to ASP. NET Framework 3.5.1
- Kb2600100:hotfix applies to ASP. NET Framework 3.5 SP1 in the. NET Framework 2.0 SP2
Many of the code farm Windows Server will automatically update the installation patches, so the other city in Scenario 2 is normal, in fact, because these servers have been patched, some new shelves, reinstall the system of the server or automatically update the server is not set the problem is likely to occur such problems ...
If the server does not have operational rights or do not want to patch so troublesome, such as the code farm me, you can also add a browser definition file at the root of the site, the steps are as follows:
1, add a "app_browsers" folder;
2, add a "*.browser" suffix of the file, such as Ie10.browser;
3, add the following content in the file (the following configuration means that all devices and browsers support cookies):
<Browsers> <BrowserRefID= "Default"> <Capabilities><!--To avoid wrong detections of e.g. IE10 - <Capabilityname= "Cookies"value= "true" /> <Capabilityname= "Ecmascriptversion"value= "3.0" /> </Capabilities> </Browser> </Browsers>
This is for a site configuration, if you do not want to patch and want to do a global configuration of all sites on the server, how to deal with it? Very easy, in fact, the above has been expressed, the problem is in the IE.browser this file configuration, so we just on the original basis, plus this string "\d{2,}$", so that ASP. NET can identify IE10 user-agent. The modified configuration is as follows:
<name= "MajorVersion" match= "^[6-9]|\d{2,}$"/>
After you have finished modifying, compile the modified. browser file into an assembly and install it into the GAC under the command line, and if it is Windows Server 2008, Win7, run the command line as an administrator: C:\Windows\Microsoft.NET\ Framework\v4.0.30319\aspnet_regbrowsers.exe-i
If it is IE11, due to its user-agent "mozilla/5.0 (Windows NT 6.3; trident/7.0; rv:11.0) Like Gecko"The change is bigger, so you need to add the following string to do the matching:
<!--mozilla/5.0 (Windows NT 6.3; trident/7.0; rv:11.0) Like Gecko -<BrowserID= "Ie11preview"ParentID= "Mozilla"> <Identification> <useragentMatch= "trident/(? ') Layoutversion ' \d+). *RV: (? ') Revision ' (? ') Major ' \d+) (\. (? ') Minor ' \d+ )) " /> <useragentNonmatch= "MSIE" /> </Identification> <Capabilities> <Capabilityname= "Browser"value= "IE" /> <Capabilityname= "Layoutengine"value= "Trident" /> <Capabilityname= "Layoutengineversion"value= "${layoutversion}" /> <Capabilityname= "IsColor"value= "true" /> <Capabilityname= "ScreenBitDepth"value= "8" /> <Capabilityname= "Ecmascriptversion"value= "3.0" /> <Capabilityname= "Jscriptversion"value= "6.0" /> <Capabilityname= "JavaScript"value= "true" /> <Capabilityname= "Javascriptversion"value= "1.5" /> <Capabilityname= "W3cdomversion"value= "1.0" /> <Capabilityname= "exchangeomasupported"value= "true" /> <Capabilityname= "ActiveXControls"value= "true" /> <Capabilityname= "Backgroundsounds"value= "true" /> <Capabilityname= "Cookies"value= "true" /> <Capabilityname= "Frames"value= "true" /> <Capabilityname= "Javaapplets"value= "true" /> <Capabilityname= "Supportscallback"value= "true" /> <Capabilityname= "Supportsfileupload"value= "true" /> <Capabilityname= "Supportsmultilinetextboxdisplay"value= "true" /> <Capabilityname= "Supportsmaintainscrollpositiononpostback"value= "true" /> <Capabilityname= "Supportsvcard"value= "true" /> <Capabilityname= "Supportsxmlhttp"value= "true" /> <Capabilityname= "Tables"value= "true" /> <Capabilityname= "SupportsAccesskeyAttribute"value= "true" /> <Capabilityname= "TagWriter"value= "System.Web.UI.HtmlTextWriter" /> <Capabilityname= "VBScript"value= "true" /> <Capabilityname= "Revmajor"value= "${major}" /> <Capabilityname= "Revminor"value= "${minor}" /> </Capabilities></Browser>
Kick's done!
Happiness is so sudden ~ ~ ~