• λ我爱Aspx >> Asp.Net >> ASP中使用ServerVariables集合详解
  • ASP中使用ServerVariables集合详解

  • :aspxer  Դ:internet  :2007-5-15 20:46:59  ؼ:asp
  • 或者根据特定的方言,重定向页面:

    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集合的值

    可以访问和使用ServerVariables集合中的任何一成员,控制ASP页面响应一个请求的方式。可以检查一个浏览者访问站点时使用的是否是缺省端口80或还是另一个。在这个例子里,寻找通过端口443的访问——这个端口提供的是安全套接字层(Secure Socket Layer,SSI)访问(和其他的协议),且将它们重定向到一个相应的页面。

    If Request.ServerVariables(“SERVER_PORT”) = “443”) Then

    Response.Redirect “/securesite/default.asp” ‘Secure user

    Else

    Response.Redirect “/normalsite/default.asp” ‘Non-secure user

    End If

    假如要求浏览者注册且由服务器验证(而不是允许他们在Web服务器的IUSER帐号下匿名访问,这个问题将在后面章节中详细讨论),可以查询用户名称,来判定正在与我们打交道的用户是谁,是否装载页面给该用户。例如,下面的这个代码将只向名为Administrator的用户显示管理链接。

    ...

    <A HREF=”dispcnfg.asp”>Change Display Configuration</A>

    <A HREF="http://dev.21tx.com/2005/11/16/”dispcolr.asp”>Change" Display Colors</A>

    <A HREF="http://dev.21tx.com/2005/11/16/”keyboard.asp”>Change" Keyboard Configuration</A>

    <%

    If Request.ServerVariables(“AUTH_USER”) _

    = Ucase(Request.ServerVariables(“SERVER_NAME”)) & “\Administrator” Then

    %>

    <A HREF="http://dev.21tx.com/2005/11/16/”allusers.asp”>Administer" All Users</A>

    <A HREF="http://dev.21tx.com/2005/11/16/”usrlogon.asp”>Administer" Logon Information</A>

    <%

    End If

    %>

    ...

    注意ASP不填写ServerVariables集合直到你访问其中的一个成员。首次访问该集合的一个成员将使IIS得到它的全部,应只在需要时才使用ServerVariables集合。

    上一篇: ASP内置对象Request和Response详解

    下一篇: 借他人的程序造自己的家园 菜鸟也会架论坛

    1 2 下一页

    Ҷƪл˵?
  • һƪ在ASP中访问和更新Cookies集合
    һƪ在ASP中操作HTTP报头方法分析