HttpCapabilitiesBase.Version 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
以字符串形式获取浏览器的完整版本号(整数和小数)。
public:
property System::String ^ Version { System::String ^ get(); };
public string Version { get; }
member this.Version : string
Public ReadOnly Property Version As String
属性值
浏览器的完整版本号(字符串形式)。
示例
下面的代码示例演示如何确定 Version 浏览器。 属性 MajorVersion 和 MinorVersion 属性是串联的,结果用于确定浏览器版本是否大于 5.01。
<%@ page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object Sender, EventArgs e)
{
CheckBrowserCaps();
}
void CheckBrowserCaps()
{
String labelText = "";
System.Web.HttpBrowserCapabilities myBrowserCaps = Request.Browser;
if (Double.Parse(((System.Web.Configuration.HttpCapabilitiesBase)myBrowserCaps).Version, System.Globalization.CultureInfo.InvariantCulture) > 5.01)
{
labelText = "Browser version is greater than 5.01.";
}
else
{
labelText = "Browser version is less than or equal to 5.01.";
}
Label1.Text = labelText;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Browser Capabilities Sample</title>
</head>
<body>
<form runat="server" id="form1">
<div>
Browser Capabilities:
<p/><asp:Label ID="Label1" Runat="server" />
</div>
</form>
</body>
</html>
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
CheckBrowserCaps()
End Sub
Function CheckBrowserCaps()
Dim labelText As String = ""
Dim myBrowserCaps As System.Web.HttpBrowserCapabilities = Request.Browser
If Double.Parse((CType(myBrowserCaps, System.Web.Configuration.HttpCapabilitiesBase)).Version, System.Globalization.CultureInfo.InvariantCulture) > 5.01 Then
labelText = "Browser version is greater than 5.01."
Else
labelText = "Browser version is less than or equal to 5.01."
End If
Label1.Text = labelText
End Function 'CheckBrowserCaps
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Browser Capabilities Sample</title>
</head>
<body>
<form runat="server" id="form1">
<div>
Browser Capabilities:
<p/><asp:Label ID="Label1" Runat="server" />
</div>
</form>
</body>
</html>
注解
该 Version 属性返回一个字符串。 在某些情况下,该 Version 属性可能包含字母字符,就像是 Beta 版本(如“7.0b”)的浏览器或客户端设备的情况一样。 若要正确获取版本作为可用于数值比较的数据类型,请 MajorVersion 连接和 MinorVersion 属性值。