Click here to Skip to main content
13,151,998 members (43,243 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

74.8K views
5 bookmarked
Posted 9 Apr 2013

How to get URL and QueryString value in an ASP.NET page

, 9 Apr 2013
Rate this:
Please Sign up or sign in to vote.
How to use the CLASIC ASP code for different values from the server variables.

Introduction

Generally we pass the querystring values from ASPX page to ASPX pages in .NET. We can also pass the value through ASP pages. Now the question is how to get the URL and querystring value in the ASP page.

QueryString

To get the querystring value in ASP page we can use the following code with in the server tag.

Request.ServerVariables("QUERY_STRING")

For a given URL like "http://www.mytestserver123.com/admin/ViewUserDetails.asp?userID=123" the above statement will result as "userID=123".

URL

To get the base URL we can use:

Request.ServerVariables("URL")

For a given URL like "http://www.mytestserver123.com/admin/ViewUserDetails.asp?userID=123" the above statement will result as "http://www.mytestserver123.com".

Any physical path between URL and QueryString

To get the Physical path if any, between base URL and QueryString we can get by:

Request.ServerVariables("PATH_INFO")

For a given URL like "www.mytestserver123.com/admin/ViewUserDetails.asp?userID=123" the above statement will result as "/admin/ViewUserDetails.asp".

To get the whole URL we need to concatenate the above 3. Get the three in separate variables and then concatenate them all in "URL + PATH_INFO + QUERY_STRING". This will result in the whole URL.

There are many more thing we can get from the URL. They are as follows:

VariableDescription
ALL_HTTPReturns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized
ALL_RAWReturns all headers in raw form
APPL_MD_PATHReturns the meta base path for the application for the ISAPI DLL
APPL_PHYSICAL_PATHReturns the physical path corresponding to the meta base path
AUTH_PASSWORDReturns the value entered in the client's authentication dialog
AUTH_TYPEThe authentication method that the server uses to validate users
AUTH_USERReturns the raw authenticated user name
CERT_COOKIEReturns the unique ID for client certificate as a string
CERT_FLAGSbit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the Certification authority of the client certificate is not valid
CERT_ISSUERReturns the issuer field of the client certificate
CERT_KEYSIZEReturns the number of bits in Secure Sockets Layer connection key size
CERT_SECRETKEYSIZEReturns the number of bits in server certificate private key
CERT_SERIALNUMBERReturns the serial number field of the client certificate
CERT_SERVER_ISSUERReturns the issuer field of the server certificate
CERT_SERVER_SUBJECTReturns the subject field of the server certificate
CERT_SUBJECTReturns the subject field of the client certificate
CONTENT_LENGTHReturns the length of the content as sent by the client
CONTENT_TYPEReturns the data type of the content
GATEWAY_INTERFACEReturns the revision of the CGI specification used by the server
HTTP_<HeaderName>Returns the value stored in the header HeaderName
HTTP_ACCEPTReturns the value of the Accept header
HTTP_ACCEPT_LANGUAGEReturns a string describing the language to use for displaying content
HTTP_COOKIEReturns the cookie string included with the request
HTTP_REFERERReturns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty
HTTP_USER_AGENTReturns a string describing the browser that sent the request
HTTPSReturns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel
HTTPS_KEYSIZEReturns the number of bits in Secure Sockets Layer connection key size
HTTPS_SECRETKEYSIZEReturns the number of bits in server certificate private key
HTTPS_SERVER_ISSUERReturns the issuer field of the server certificate
HTTPS_SERVER_SUBJECTReturns the subject field of the server certificate
INSTANCE_IDThe ID for the IIS instance in text format
INSTANCE_META_PATHThe meta base path for the instance of IIS that responds to the request
LOCAL_ADDRReturns the server address on which the request came in
LOGON_USERReturns the Windows account that the user is logged into
PATH_INFOReturns extra path information as given by the client
PATH_TRANSLATEDA translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping
QUERY_STRINGReturns the query information stored in the string following the question mark (?) in the HTTP request
REMOTE_ADDRReturns the IP address of the remote host making the request
REMOTE_HOSTReturns the name of the host making the request
REMOTE_USERReturns an unmapped user-name string sent in by the user
REQUEST_METHODReturns the method used to make the request
SCRIPT_NAMEReturns a virtual path to the script being executed
SERVER_NAMEReturns the server's host name, DNS alias, or IP address as it would appear in self-referencing URLs
SERVER_PORTReturns the port number to which the request was sent
SERVER_PORT_SECUREReturns a string that contains 0 or 1. If the request is being handled on the secure port, it will be 1. Otherwise, it will be 0
SERVER_PROTOCOLReturns the name and revision of the request information protocol
SERVER_SOFTWAREReturns the name and version of the server software that answers the request and runs the gateway
URLReturns the base portion of the URL

This above table contains the variables and its descriptions for the result to be produced. Here is a change to learn something different. Let's grab this out.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sisir Patro
Software Developer
India India
Learn the base not only the requirement related things for quick fixing and make others learn the exact thing always...

You may also be interested in...

Comments and Discussions

 
SuggestionSmall correction Pin
Adam_Finster25-Jun-13 18:19
memberAdam_Finster25-Jun-13 18:19 
GeneralRe: Small correction Pin
sisirp8825-Jun-13 20:18
professionalsisirp8825-Jun-13 20:18 
GeneralMy vote of 5 Pin
sisirp8814-Apr-13 23:44
professionalsisirp8814-Apr-13 23:44 
GeneralMy vote of 5 Pin
Singh_Vinay14-Apr-13 23:43
professionalSingh_Vinay14-Apr-13 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 9 Apr 2013
Article Copyright 2013 by Sisir Patro
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid