【发布时间】:2011-07-25 14:12:11
【问题描述】:
在我们从 .NET 3.5 升级到 .NET 4.0 后,我们发现一些 Safari 浏览器无法交叉验证我们的网站。
经过大量调查,结果证明是 ASP.NET 正确识别 Safari 浏览器的问题。 ASP.NET 将某些 Safari(可能是其他基于 WebKit 的浏览器)标识为 Mozilla 版本 0.0。不支持 cookie、框架、JavaScript 等的浏览器。.NET 3.5 识别这些浏览器没有任何问题。
我们已将测试简化为一个简单的 HTTP 处理程序(在 vanilla 4.0 网站上运行),它只返回请求者的浏览器功能。
以下是一些无法识别的用户代理(它们被识别为 Mozilla 0.0):
Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_5_8;+en-us)+AppleWebKit/533.19.4+(KHTML,+like+Gecko)+Version/5.0.3+Safari/533.19.4Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_2;+en-us)+AppleWebKit/531.9+(KHTML,+like+Gecko)Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_7;+en-us)+AppleWebKit/533.20.25+(KHTML,+like+Gecko)+Version/5.0.4+Safari/533.20.27Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_6;+en-us)+AppleWebKit/533.18.1+(KHTML,+like+Gecko)
处理程序代码如下所示:
<%@ WebHandler Language="C#" Class="PowershellTemporaryHandler" %>
using System;
using System.Web;
using System.Web.Security;
public class PowershellTemporaryHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
HttpBrowserCapabilities hbc = context.Request.Browser;
context.Response.Write("Type=" + hbc.Type + "<br>");
context.Response.Write("Name=" + hbc.Browser + "<br>");
context.Response.Write("Version=" + hbc.Version + "<br>");
context.Response.Write("Major Version=" + hbc.MajorVersion + "<br>");
context.Response.Write("Minor Version=" + hbc.MinorVersion + "<br>");
context.Response.Write("Platform=" + hbc.Platform + "<br>");
context.Response.Write("Is Beta=" + hbc.Beta + "<br>");
context.Response.Write("Is Crawler=" + hbc.Crawler + "<br>");
context.Response.Write("Is AOL=" + hbc.AOL + "<br>");
context.Response.Write("Is Win16=" + hbc.Win16 + "<br>");
context.Response.Write("Is Win32=" + hbc.Win32 + "<br>");
context.Response.Write("Supports Tables=" + hbc.Tables + "<br>");
context.Response.Write("Supports cookies=" + hbc.Cookies + "<br>");
context.Response.Write("Supports VBScript=" + hbc.VBScript + "<br>");
context.Response.Write("Supports Frames=" + hbc.Frames + "<br>");
context.Response.Write("Supports JavaScript=" + hbc.EcmaScriptVersion.ToString() + "<br>");
context.Response.Write("Supports Java Applets=" + hbc.JavaApplets + "<br>");
context.Response.Write("Supports ActiveX Controls=" + hbc.ActiveXControls + "<br>");
context.Response.Write("User Agent=" + context.Request.UserAgent + "<br>");
}
}
我们对互联网上没有提及这个问题感到困惑。似乎我们需要将浏览器定义添加到 framework/config/browsers 文件夹或网站级别的 App_Browsers 文件夹,但我们需要调整浏览器定义以使 .NET 4.0 网站正常运行似乎很奇怪.
有人对这个问题有任何经验吗?
【问题讨论】:
-
我在使用 .net 3.5 和 4.0 时也遇到了这个问题。无法识别的用户代理示例 - “Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27”。获取 Mozilla 0.0。
-
@Magpie 下面user1777803提供的解决方案你试过了吗?
-
@Knickerless-Noggins 抱歉,这是很久以前的事了,我无法可靠地回答。
标签: .net-4.0 safari cross-browser asp.net-4.0