Several common ways to use ServerVariables collections

Source: Internet
Author: User
Tags contains servervariables version port number
server| collection 1. " Self-referencing page


the value returned in the ServerVariables collection contains the details of the Web server and the path information for the current page. You can use this information to create a page anywhere. For example, to create a "self reference" page, this page can call itself to complete another task, we can use the following code:


<form action= "<% = Request.ServerVariables (" path_info ")%>" method= "POST" >


the same effect can be obtained using the HTTP "script_name" Value:


<form action= "<% = Request.ServerVariables (" Script_name ")%>" method= "POST" >








2. Create a complete URL that includes the port number (in this case, not the standard value 80):


Strfullurl = "http://" & Request.ServerVariables ("Local_addr") _


& ":" & Request.ServerVariables ("Server_port") _


& Request.ServerVariables ("Path_info")








3. Use the "Http_user_agent" value in the ServerVariables collection to obtain a user agent string that can be used to determine the browser and version of the visitor:


Strua = Request.ServerVariables ("http_user_agent")


Response.Write "User Agent string is <b>" & Strua & "</B>"





4. Detecting the language of the browser


Another useful value in the ServerVariables collection is "Http_accept_language", which contains a language code that is specified when the browser is installed, or hard-coded into the user's regional version. Examples of language codes are en-US (UK, USA), De-at (Germany, Australia) and ES-PE (Spain, Peru).


Strlocale = Lcase (Left (Request.ServerVariables ("Http_accept_language"), 2)








Note ASP does not fill in the ServerVariables collection until you access one of the members. Accessing one member of the collection for the first time will give IIS all of it and use the ServerVariables collection only when needed.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.