首页 > 编程 > .NET > 正文

技巧:在ASP.NET页中检测浏览器类型

2024-07-10 13:08:36
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

本文引自vs帮助文档
查询 browser 属性,
该属性包含一个 httpbrowsercapabilities 对象。
在 http 请求过程中,该对象会从浏览器或客户端设备中获取信息,
以便让您的应用程序知道浏览器或客户端设备提供的支持类型和级别。
该对象随后使用强类型属性和泛型名称值字典公开有关浏览器功能的信息。

下面的代码示例演示如何在页上的文本框中显示浏览器信息。
=======
visual basic
=======
private sub button1_click(byval sender as system.object, _
       byval e as system.eventargs) handles button1.click
    dim s as string = ""
    with request.browser
        s &= "browser capabilities" & vbcrlf
        s &= "type = " & .type & vbcrlf
        s &= "name = " & .browser & vbcrlf
        s &= "version = " & .version & vbcrlf
        s &= "major version = " & .majorversion & vbcrlf
        s &= "minor version = " & .minorversion & vbcrlf
        s &= "platform = " & .platform & vbcrlf
        s &= "is beta = " & .beta & vbcrlf
        s &= "is crawler = " & .crawler & vbcrlf
        s &= "is aol = " & .aol & vbcrlf
        s &= "is win16 = " & .win16 & vbcrlf
        s &= "is win32 = " & .win32 & vbcrlf
        s &= "supports frames = " & .frames & vbcrlf
        s &= "supports tables = " & .tables & vbcrlf
        s &= "supports cookies = " & .cookies & vbcrlf
        s &= "supports vbscript = " & .vbscript & vbcrlf
        s &= "supports javascript = " & _
            .ecmascriptversion.tostring() & vbcrlf
        s &= "supports java applets = " & .javaapplets & vbcrlf
        s &= "supports activex controls = " & .activexcontrols & _
            vbcrlf
    end with
    textbox1.text = s
end sub

=====
c#
=====
private void button1_click(object sender, system.eventargs e)
{
    system.web.httpbrowsercapabilities browser = request.browser;
    string s = "browser capabilities<br />"
        + "type = "                    + browser.type + "<br />"
        + "name = "                    + browser.browser + "<br />"
        + "version = "                 + browser.version + "<br />"
        + "major version = "           + browser.majorversion + "<br />"
        + "minor version = "           + browser.minorversion + "<br />"
        + "platform = "                + browser.platform + "<br />"
        + "is beta = "                 + browser.beta + "<br />"
        + "is crawler = "              + browser.crawler + "<br />"
        + "is aol = "                  + browser.aol + "<br />"
        + "is win16 = "                + browser.win16 + "<br />"
        + "is win32 = "                + browser.win32 + "<br />"
        + "supports frames = "         + browser.frames + "<br />"
        + "supports tables = "         + browser.tables + "<br />"
        + "supports cookies = "        + browser.cookies + "<br />"
        + "supports vbscript = "       + browser.vbscript + "<br />"
        + "supports javascript = "     +
            browser.ecmascriptversion.tostring() + "<br />"
        + "supports java applets = "   + browser.javaapplets + "<br />"
        + "supports activex controls = " + browser.activexcontrols
              + "<br />";
    response.write(s);
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表