Using ServerVariables Collection in ASP

Source: Internet
Author: User
Tags servervariables port number

When discussing the content of the request object, one of the collections to be studied is the ServerVariables collection. This collection contains a combination of two values, one that accompanies the page request from the client to the server's HTTP header, and the value provided by the server itself when it receives the request.

The Self-References 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 with the "script_name" value of http:

<FORM ACTION=”<% = Request.ServerVariables(“SCRIPT_NAME”) %>” METHOD=”POST”>

Using the element to open a different page, you can use:

...

<%
strFullPath = Request.ServerVariables(“PATH_INFO”)
‘Strip off the file name
strPathOnly = Left(strFullPath, InStrRev(strFullPath, “/”))
strNextPage = strPathOnly & “pages/next_page.asp”
%>
...
<A HREF=”<% = strNextPage %>”>Next Page</A>
...

These instances work correctly even if the name or location of the original page changes, because the path information for the current page is used (of course, the second example fails when the name of the detached target page changes).

In other words, if you automatically create URLs for a child session of a search engine, you can collect some of the servervariable values:

strFullURL = http:// & Request.ServerVariables(“LOCAL_ADDR”) _ & “:” &Request.ServerVariables(“SERVER_PORT”) _ & Request.ServerVariables(“PATH_INFO”)

This will create a complete URL that includes the port number (in this case, not the standard value 80). For example, the result might be:

Http://194.74.60.254:1768/thispath/thispage.asp

Related Article

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.