错误和修复:ASP.NET无法检测到IE10,导致_doPostBack是未定义JavaScript错误或保持FF5滚动条位置

__doPostBack error in IE10

Browser version numbers continue to march on. IE9 is here, IE10 is coming, Firefox 5 and 6 are here with 7 and 8 in the wings, Opera's on 11, and Chrome is on, I dunno, somewhere between 14 and 50. Regardless, we'll all be on version 99 before The Singularity.

浏览器版本号继续前进。 IE9即将发布IE10即将发布Firefox 5和6即将发布其中7和8即将发布,Opera启用11,Chrome启用,我不知道,介于14到50之间。无论如何,我们都将使用版本99在奇点之前。

There is a bug in the browser definition files that shipped with .NET 2.0 and .NET 4, namely that they contain definitions for a certain range of browser versions. But the versions for some browsers (like IE 10) aren't within those ranges any more. Therefore, ASP.NET sees them as unknown browsers and defaults to a down-level definition, which has certain inconveniences, like that it does not support features like JavaScript.

.NET 2.0和.NET 4附带的浏览器定义文件中存在一个错误,即它们包含特定范围浏览器版本的定义。 但是某些浏览器(例如IE 10)的版本已不在这些范围内。 因此,ASP.NET将它们视为未知的浏览器,并且默认为下级定义,该定义具有某些不便之处,例如它不支持JavaScript之类的功能。

If you want to see this for yourself, create a new, blank Web site (e.g. in Visual Studio 2010), add a control that requires JavaScript for postback (good example: <asp:LinkButton>), and then run the site using IE9 (where it works) and IE10 (where it won't). View the page source and compare the HTML and JavaScript sent to each browser.

如果您想亲自查看,请创建一个新的空白网站(例如在Visual Studio 2010中),添加一个需要JavaScript进行回发的控件(很好的示例:<asp:LinkBut​​ton>),然后使用IE9运行该网站(适用于该产品)和IE10(适用于该产品)。 查看页面源,并比较发送给每个浏览器HTML和JavaScript

A similar bug affects Firefox versions 5 and above, where support for using JavaScript to reposition the scrollbar in the browser is not detected. This basically breaks the MaintainScrollbackPositionOnPostBack property for Web Forms pages.

类似的错误会影响Firefox 5及更高版本,在该版本中未检测到使用JavaScript在浏览器中重新定位滚动条的支持。 这基本上破坏了Web窗体页面的MaintenanceScrollbackPositionOnPostBack属性。

These "misdetection" bugs affect Web Forms pages in both ASP.NET 2 and ASP.NET 4. If you are using ASP.NET Web Pages, or if you're using ASP.NET MVC or ASP.NET Web Pages and are not using the Browser object to detect JavaScript support, you will not be affected.

这些“错误检测”错误会影响ASP.NET 2和ASP.NET 4中的Web窗体页面。如果您使用的是ASP.NET网页,或者使用的是ASP.NET MVC或ASP.NET网页,而没有使用浏览器对象检测JavaScript支持,您将不会受到影响。

修正 (Fixes)

There are two ways to fix this: one is a machine-wide fix, the other is a way to fix individual sites.

有两种解决方法:一种是计算机范围的修复,另一种是修复单个站点的方法。

机器范围内的修复 (Machine-wide fixes)

We're releasing a hotfix that will fix these, which you'll be able to get to via some KB articles. These KBs with fixes are live and are the best way to update your system. The fixes solve the browser-detection issue forever for all sites on a machine. These will be rolled up into future versions of the framework and will eventually also be on Windows Update.

我们将发布一个修复程序,将修复这些问题,您可以通过一些知识库文章获得此修复程序。 这些带有修复程序的知识库是实时的,并且是更新系统的最佳方法。 该修补程序将永远解决计算机上所有站点的浏览器检测问题。 这些将汇总到该框架的将来版本中,并最终也将在Windows Update上。

What the fixes do is update the ie.browser and firefox.browser files in \Windows\Microsoft.NET\Framework\<version>\Config\Browsers with new and future-proofed versions of these browser definitions. Nothing else is affected.

该修补程序的作用是更新\ Windows \ Microsoft.NET \ Framework \ <version> \ Config \ Browsers中ie.browserfirefox.browser文件。 这些浏览器定义的新版本和面向未来的版本。 没有其他影响。

仅网站修复 (Site-only fixes)

App_Browsers

If you don't have access to the whole machine and/or just want to update a single project, use NuGet to install the App_BrowsersUpdate package. Your site structure in Solution Explorer will then look like the image at right. Note that NuGet uses .NET 4, so for systems that have only .NET 2, you'll need to get the ZIP file and put the new browser files in App_Browsers manually.

如果您无权访问整个计算机和/或仅想更新单个项目,请使用NuGet安装App_BrowsersUpdate软件包。 解决方案资源管理器中的站点结构将如右图所示。 请注意,NuGet使用.NET 4,因此对于只有.NET 2的系统,您需要获取ZIP文件并将新的浏览器文件手动放入App_Browsers中。

Updating the whole machine is the preferred way to fix this.

更新整个计算机是解决此问题的首选方法。

概要 (Summary)

  • ASP.NET might not recognize the most current versions of some browsers, and will consequently treat them as down-level browsers. (Basically: no JavaScript.)

    ASP.NET可能无法识别某些浏览器的最新版本,因此会将它们视为下层浏览器。 (基本上:没有JavaScript。)
  • The fix is to get updated browser-definition files.

    解决方法是获取更新的浏览器定义文件。
  • You can install a machine-wide fix or just fix individual projects.

    您可以安装计算机范围的修复程序,也可以仅修复单个项目。

If you're interested in more detail than you need, I’ve uploaded the updated versions of firefox.browser and ie.browser files that are expected to ship with the next version of ASP.NET. The files and source is up at my BitBucket repo if you are interested in the details.

如果您对所需的详细信息感兴趣,我已上载了预期版本的ASP.NET附带的firefox.browser和ie.browser文件的更新版本。 如果您对详细信息感兴趣,文件和源位于我的BitBucket存储库中。

翻译自: https://www.hanselman.com/blog/bug-and-fix-aspnet-fails-to-detect-ie10-causing-dopostback-is-undefined-javascript-error-or-maintain-ff5-scrollbar-position

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值