我的代码是:
protected void btn_log_Click(object sender, EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string opSystem = browser.Platform;
string browserName = browser.Browser;
string Version = browser.Version;
}
我的问题:我的IE11版本为0.00,浏览器名称为Mozilla
答案 0 :(得分:0)
您可以尝试从UserAgent获取浏览器版本。像这样的代码:
var userAgent = HttpContext.Current.Request.UserAgent;
var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
Label1.Text = userBrowser.Browser + "--" + userBrowser.Version;
这是一篇有关how to detect browsers in ASP.NET with browser files的文章,您也可以检查一下。
此外,我认为您还可以使用JavaScript检测浏览器版本,可以检查this article。
答案 1 :(得分:0)
html
<input id="lblver" type="hidden" runat="server" />
java script
<script type="text/javascript">
var rv = -1;
var lblver = '<%= lblver.ClientID %>';
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
else if (navigator.appName == 'Netscape') {
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
document.getElementById(lblver).value = rv;
</script>
c# code
Version = lblver.Value;