ASP中ServerVariables集合用法详解(2)

作者:CODEOF 来源:21tx.com 时间:2007-09-14 10:26:00 

使用HTTP_USER_AGENT来检测浏览器的版本
  
    ServerVariables集合中,另外一个有用的值是用户浏览器的用户代理字符串。在“Detecting the Browser Type”页面(browsertype.asp),使用ServerVariables集合中的“HTTP_USER_AGENT”值来获得用户代理字符串,一些脚本用来解析该信息并寻找生产厂家名称和浏览器版本。


<% 
  strUA = Request.ServerVariables(“HTTP_USER_AGENT”) 
  Response.Write “The User Agent string is <B>” & strUA & “</B> 
  ” 
  If InStr(strUA, “MSIE”) Then 
  Response.Write “To upgrade your browser go to “_ 
  & “<A HREF=” & Chr(34) & http://www.microsoft.com/ie/”_ 
  & Chr(34) & “>http://www.microsoft.com/ie/<A> 
  ” 
  intVersion = Cint(Mid(strUA, InStr(strUA, “MSIE”) + 5, 1)) 
  If intVersion >=4 Then 
  Response.Write “You can use Microsoft Dynamic HTML” 
  End If 
  Else 
  If InStr(strUA, “Mozilla”) Then 
  If InStr(strUA, “compatible;”) = 0 Then 
  Response.Write “Your browser is probably Navigator. You can “_ 
  & “download the latest version of Navigator from “_ 
  & “<A HREF=” & Chr(34) & http://home.netscape.com/”_ 
  & “download/”& Chr(34) & “>http://home.netscape.com”_ 
  & “/download/</A> 
  ” 
  intVersion = Cint(Mid(strUA, InStr(strUA, “/”) +1, 1)) 
  If intVersion >= 4 Then 
  Response.Write “You can probably use Netscape Dynamic HTML” 
  End If 
  Else 
  strVersion = Mid(strUA, InStr(strUA, “compatible;”) + 12) 
  strProduct = Left(strVersion, InStr(strVersion, “ “)) 
  Response.Write “Your browser is Navigator-compatible. You can”_ 
  & “search for the manufacturer using a search engine, such as”_ 
  & “<A HREF=” & Chr(34) _ 
  & “http://www.altavista.digital.com/CGI-bin/query?q=”_ 
  & strProduct _ 
  & Chr(34) & “>http://www.altavista.com/</A> 
  ” 
  End If 
  End If 
  End If 
  %> 


对IE 5.0和Navigator 4.61的搜索结果分别不同,对于其他厂家的浏览器,可以得到一个链接在Alta Vista Web站点自动开始搜索厂家的名称。
  
    注意,Netscape在用户代理字符串中不提供厂家的名称,因而无法绝对保证一个浏览器一定是Navigator。 

使用HTTP_ACCEPT_LANGUAGE来检测浏览器的语言
  
    ServerVariables集合中另外一个有用的值是“HTTP_ACCEPT_LANGUAGE”,它包含了一个当浏览器安装时指定的,或硬编码进用户的地区版本的语言代码。语言代码的例子有en-us(英国、美国)、de-at(德国、澳大利亚)和es-pe(西班牙、秘鲁)。
  
    语言代码可以是一般的且省略方言标识:例如,在我们的站点Wrox者,大批浏览者都是将en(英语)作为语言代码。
  
    因此,可以检测语言代码并自动装载一个合适的特定地区或指定语言版本的页面。

StrLocale = Lcase(Left(Request.ServerVariables(“HTTP_ACCEPT_LANGUAGE”),2)) 
  Select Case strLocale 
   Case “en”: Response.Redirect “http://uk_site.co.uk/” 
   Case “de”: Response.Redirect “http://de_site.co.de/” 
   Case “fr”: Response.Redirect “http://fr_site.co.fr/” 
   ‘... etc 
   Case Else: Response.Redirect “http://us_sitel.com/” 
  End Select 


或者根据特定的方言,重定向页面:


strLocale = Lcase(Request.ServerVariables(“HTTP_ACCEPT_LANGUAGE”)) 
  Select Case strLocale 
   Case “en-gb”: Response.Redirect “http://uk_site.co.uk/” 
   Case “en-us”: Response.Redirect “http://us_site.com/” 
   Case “es-pe”: Response.Redirect “http://es_site2.co.pe/” 
   ‘... 
   Case Else: Response.Redirect “http://us_site1.com/” 
  End Select 


标签:ServerVariables,asp
0
投稿

猜你喜欢

  • Python Pillow(PIL)库的用法详解

    2022-01-31 13:43:26
  • 一文教你用python编写Dijkstra算法进行机器人路径规划

    2021-09-16 21:09:28
  • 用python实现文件备份

    2022-04-19 06:28:19
  • Django def clean()函数对表单中的数据进行验证操作

    2023-08-16 00:31:47
  • 使用python将微信image下.dat文件解密为.png的方法

    2022-11-12 06:39:38
  • 常见JS前端接口校验方式总结

    2024-04-17 10:00:00
  • Python+Opencv实现计算闭合区域面积

    2023-03-17 03:02:44
  • Kali Linux 2022.1安装和相关配置教程(图文详解)

    2023-11-10 15:54:50
  • 对python产生随机的二维数组实例详解

    2022-10-29 14:13:28
  • MySQL手动安装方法与中文解决方案

    2011-04-25 18:21:00
  • MySQL找出未提交事务的SQL实例浅析

    2024-01-23 04:08:25
  • MySQL 中这么多索引该怎么选择

    2024-01-17 12:58:54
  • 浅述七大主流数据库

    2011-08-05 18:21:27
  • Jar包一键重启的Shell脚本及新服务器部署的一些经验分享

    2023-06-24 19:01:08
  • 修改mysql默认字符集的两种方法详细解析

    2024-01-27 01:48:17
  • Go实现一个配置包详解

    2024-05-22 10:29:57
  • vue router 动态路由清除方式

    2024-05-08 10:12:22
  • JavaScript实现简易轮播图最全代码解析(ES5)

    2024-04-16 10:40:22
  • 玩转python爬虫之爬取糗事百科段子

    2022-09-23 12:20:52
  • ASP.NET程序中用Repeater实现分页

    2024-05-09 09:02:48
  • asp之家 网络编程 m.aspxhome.com