在asp中检测HTTP_USER_AGENT

时间:2015-04-10 14:26:48

标签: asp-classic user-agent

我需要在asp网站上检测所使用的设备是否是平板电脑。 我想知道哪个用户代理用于此

现在我这样做

agent = Request.ServerVariables("HTTP_USER_AGENT")

    Set reg = New RegExp
    With reg
        .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)"
        .IgnoreCase = True
        .Global = True
    End With

    match = reg.Test(agent)

    If match Then
        session("IsMobileBrowser") = 1
    Else
        session("IsMobileBrowser") = 0
    End If

由于

1 个答案:

答案 0 :(得分:0)

我们正在使用此API来检测我们的经典asp网站上的移动设备,它运行良好。 https://code.google.com/p/mobileesp/source/browse/#svn/JavaScript

使用DetectTierTablet功能检测平板电脑。

对代码的更改很少,我们能够将其包含在服务器端。只需要替换:

if (navigator && navigator.userAgent)
    this.uagent = navigator.userAgent.toLowerCase();

if (Request.ServerVariables("HTTP_USER_AGENT").Item != null)
    this.uagent = Request.ServerVariables("HTTP_USER_AGENT").Item.toLowerCase();