Response.Write(Request.ServerVariables["HTTP_USER_AGENT"]);(貌似ASP上也可用这个)
或
Response.Write(Request.UserAgent);
我的是IE7输出:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SE 1.X; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; SE 1.X)
谷歌浏览器输出:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0
在后台写成公共方法调用 (须添加引用)
public static int getBrowser()
{
string BrowserInfo = HttpContext.Current.Request.UserAgent;
if (BrowserInfo.Contains("MSIE 7.0"))
{//IE7
return 1;
}
else if (BrowserInfo.Contains("MSIE 6.0"))
{//IE6
return 2;
}
else if (BrowserInfo.Contains("Firefox"))
{//IE6
return 3;
}
else if (BrowserInfo.Contains("Chrome"))
{//谷歌
return 4;
}
return 5;
}