百年一遇的奇怪问题:当IE遇上.NET Framework 4.5

[来源] 达内    [编辑] 达内   [时间]2012-09-14

一个是微软的 IE,一个是微软的 .NET Framework 4.5,竟然出现如此离奇的问题,不得不让人想起一句诗句:“本是同根生,相煎何太急”

一个是微软的 IE,一个是微软的 .NET Framework 4.5,竟然出现如此离奇的问题,不得不让人想起一句诗句:“本是同根生,相煎何太急”。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">下面我们来一睹这个百年一遇的奇怪问题。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题背景

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 最近将 job.cnblogs.com 项目中的 Entity Framework 升级到了 5.0,据说 EF 5.0 在 .NET Framework 4.5 之下性能会有大幅提升(相关博文 ),于是在服务器上安装了 .NET Framework 4.5。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 安装后发现,.NET Framework 4.5 并没有在 C:\Windows\Microsoft.NET 中创建新的文件夹,都安装在了 .NET Framework 4.0 文件夹中,并且更新了 .NET Framework 4.0 中的很多 dll 文件,比如 System.Web.dll, System.Web.Routing.dll...

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">老规矩,安装后需要重启服务器,重启后测试了所有站点(IIS 7 + ASP.NET MVC 3 + WebForms),未发现任何异常。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题现象

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 接着,陆陆续续有园友反映访问闪存(home.cnblogs.com/ing/)很卡,开始以为是网络线路问题。后来发现出现问题的用户用的都是 IE 8,以为是 js 代码的浏览器兼容问题引起的,于是检查  js  代码,在这个过程中无意间重现了这个问题, 而且用的是 IE 9。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">用户所说的“很卡”究竟是什么样一种情况,请看下图:

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">“卡”也就是浏览器标签窗口上的小图标一直处于旋转状态(等待服务器响应)。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 按 F12 打开 IE 的开发者工具,发现浏览器发出请求后,服务器一直没有响应。说明这个问题与 js 没有任何关系,是服务器端请求处理问题。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> (这时你也许会有疑问,这个问题我们自己怎么没发现?不就是点一下 IE,几秒钟的事情。可是问题没这么简单,用 IE 第一次访问一切正常,问题出在后续的请求,通常是第三次请求。我们主要用的浏览器是 Chrome 与 Firefox,所以测试时,用 IE 打开一下,看没问题就关掉了。)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 出现“卡”的问题后,即使重新打开浏览器标签也是同样的问题,唯一的解决方法是退出整个IE,并重新打开。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题奇怪之处

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">问题奇怪之一: 服务器是微软的 ASP.NET 环境,出问题的不是其他浏览器,而是微软自己的 IE 浏览器。(想不通)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">问题奇怪之二: IE 第一次请求不会出现问题,问题只出现在后续请求中。(难道与浏览器的Last-Modified有关)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">问题奇怪之三: 同一台服务器,有多个站点,只有这一个站点会出现这个问题。同一个站点(home.cnblogs.com),只有主页与闪存相关页面会出现这个问题。(可能是某个操作引起的)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">问题奇怪之四: WebForms 与 MVC 都会出现这个问题。这个站点是 WebForms 与 ASP.NET MVC 的混合环境,出现问题的页面是 WebForms 页面,但这些页面的 ajax 是请求由 MVC 处理的,也会有同样的问题。(这个操作可能 WebForms 与 MVC 都会用到)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">问题奇怪之五:  Global.asax 中取消所有 MVC 的路由注册(routes.MapRoute),问题就消失。(这个问题可能与WebForms 与 ASP.NET MVC 的混合环境有关)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题原因确认

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 为了确认这个问题是不是 .NET Framework 4.5 引起的?我们在测试环境中将 .NET Framework 4.5 卸载。这时遇到另一 郁闷的问题,卸载 .NET Framework 4.5 之后,.NET Framework 4.0 也没了,更让人郁闷的是 IIS 中所有使用 .NET Framework 4.0 的应用程序池都被改为了 .NET Framework 2.0,这个卸载真“干净”。安装 .NET Framework 4.0  之后,问题立即消失;重新安装 .NET Framework 4.5,问题立即出现。不管具体是哪个操作引起的,.NET Framework 4.5 是罪魁祸首。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题处理

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">昨天一天的奋战没有找出具体是哪个操作引起的,今天继续努力!

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">如果实在找不出,只能先卸载 .NET Framework 4.5,重新安装 .NET Framework 4.0。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题相关代码

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">ASP.NET MVC 路由注册代码:

< div style="margin: 5px 0px; padding: 5px; background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(17, 17, 17); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
public
 static void
 RegisterRoutes(RouteCollection routes) {     routes.IgnoreRoute(
"

{resource}.axd/{*pathInfo}
"

);     routes.MapPageRoute(
"

Default"
, "", "
~/Default.aspx"
);              routes.MapRoute(         
"

DefaultMvcAjax"
,          "
ajax/{controller}/{action}/{id}
"

,          new
 { controller = ""
, action = ""

, id = ""
 }      );              routes.MapRoute(         

"IngMovileMvc
",         
"
ing/mobile/{action}/{ingListType}/{pageIndex}

",          
new { controller = "
IngMobile"
, action = "Home
"
,              ingListType 

= CNBlogs.UcHome.Entities.IngListType.all, pageIndex = 1


 }      );              routes.MapRoute(         "


DefaultMvc"
,          

"
{controller}/{action}/{id}

",          
new { controller = "
Msg"
, action = "List
", id = ""
 }      ); }
< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">出现问题的访问路径:根路径与 ing/default.aspx,这两个路径访问的都是实际的 .aspx 文件。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 问题补充

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 用 IE9 开发者工具查看请求信息,Request headers, Request body, Response headers, Response body 全为空,只有 Timings 中有内容,见下图:

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

资源下载