How to get URL and QueryString value in an ASP.NET page
2013-04-10 17:04
851 查看
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:
Variable | Description |
---|---|
ALL_HTTP | Returns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized |
ALL_RAW | Returns all headers in raw form |
APPL_MD_PATH | Returns the meta base path for the application for the ISAPI DLL |
APPL_PHYSICAL_PATH | Returns the physical path corresponding to the meta base path |
AUTH_PASSWORD | Returns the value entered in the client's authentication dialog |
AUTH_TYPE | The authentication method that the server uses to validate users |
AUTH_USER | Returns the raw authenticated user name |
CERT_COOKIE | Returns the unique ID for client certificate as a string |
CERT_FLAGS | bit0 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_ISSUER | Returns the issuer field of the client certificate |
CERT_KEYSIZE | Returns the number of bits in Secure Sockets Layer connection key size |
CERT_SECRETKEYSIZE | Returns the number of bits in server certificate private key |
CERT_SERIALNUMBER | Returns the serial number field of the client certificate |
CERT_SERVER_ISSUER | Returns the issuer field of the server certificate |
CERT_SERVER_SUBJECT | Returns the subject field of the server certificate |
CERT_SUBJECT | Returns the subject field of the client certificate |
CONTENT_LENGTH | Returns the length of the content as sent by the client |
CONTENT_TYPE | Returns the data type of the content |
GATEWAY_INTERFACE | Returns the revision of the CGI specification used by the server |
HTTP_<HeaderName> | Returns the value stored in the header HeaderName |
HTTP_ACCEPT | Returns the value of the Accept header |
HTTP_ACCEPT_LANGUAGE | Returns a string describing the language to use for displaying content |
HTTP_COOKIE | Returns the cookie string included with the request |
HTTP_REFERER | Returns 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_REFERERis empty |
HTTP_USER_AGENT | Returns a string describing the browser that sent the request |
HTTPS | Returns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel |
HTTPS_KEYSIZE | Returns the number of bits in Secure Sockets Layer connection key size |
HTTPS_SECRETKEYSIZE | Returns the number of bits in server certificate private key |
HTTPS_SERVER_ISSUER | Returns the issuer field of the server certificate |
HTTPS_SERVER_SUBJECT | Returns the subject field of the server certificate |
INSTANCE_ID | The ID for the IIS instance in text format |
INSTANCE_META_PATH | The meta base path for the instance of IIS that responds to the request |
LOCAL_ADDR | Returns the server address on which the request came in |
LOGON_USER | Returns the Windows account that the user is logged into |
PATH_INFO | Returns extra path information as given by the client |
PATH_TRANSLATED | A translated version of PATH_INFOthat takes the path and performs any necessary virtual-to-physical mapping |
QUERY_STRING | Returns the query information stored in the string following the question mark (?) in the HTTP request |
REMOTE_ADDR | Returns the IP address of the remote host making the request |
REMOTE_HOST | Returns the name of the host making the request |
REMOTE_USER | Returns an unmapped user-name string sent in by the user |
REQUEST_METHOD | Returns the method used to make the request |
SCRIPT_NAME | Returns a virtual path to the script being executed |
SERVER_NAME | Returns the server's host name, DNS alias, or IP address as it would appear in self-referencing URLs |
SERVER_PORT | Returns the port number to which the request was sent |
SERVER_PORT_SECURE | Returns 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_PROTOCOL | Returns the name and revision of the request information protocol |
SERVER_SOFTWARE | Returns the name and version of the server software that answers the request and runs the gateway |
URL | Returns the base portion of the URL |
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)相关文章推荐
- how to get all controller attribute action and parameter in asp.net mvc
- how to get url and hostname and url text in one page
- How to read the query string params of a ASP.NET raw URL?
- How To contain multiple fileds in the querystrig, DataNavigateUrlFormatString=xxx.asp?ID={0}&Name={1}
- How to get Hidden Column Value in GridView(ASP.net GridView如何获取隐藏列的值)
- How to Pop Open an image window that resizes to fit the image in ASP.net 1.x and 2.0 Beta 1
- csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C#.
- How to set the DefaultButton in a Page Based on ASP.NET Master Page
- How to get the url of a page in OpenERP?
- How to use Bundle&Minifier and bundleconfig.json in ASP.NET Core
- How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载)
- How to create UrlSlug in Asp.Net MVC
- How To Use Cookies in an ASP Page
- csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C
- How to get your ASP.NET application working in IE11
- CodeSnip: How to Get Id of the Record Using ASP.NET and SQL Server 2000
- csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net
- 海洋工作室——网站建设专家:ASP.NET: How to Convert Your Site To A MasterPage Site in 3 Steps
- How to create simple and advanced pivot tables in C# and ASP.NET
- asp.net配置报错 “An error was encountered. Please return to the previous page and try again. ”