ASP. NET background URL Retrieval

Source: Internet
Author: User
Tags servervariables

Physical path on the server disk: httpruntime. appdomainapppath virtualProgramPath:Httpruntime. appdomainappvirtualpath

Any request/httpcontext. current and other related methods can only be used in the request context or page. httpcontext. current is null. the method mentioned above is always available.

The access to global cache objects is also true.

 

 

========================================================== ========================================================== =

Example: output the Asp.net website path.

Private Void Responsehtml () .. { Stringbuilder sb = New Stringbuilder (); SB. append ( String . Format ( " Current Time: {0} " , Server. htmlencode (datetime. Now. tostring ()))); SB. append ( " <Br/> " ); SB. append ( String . Format ( " The Virtual Path of the current request: {0} " , Server. htmlencode (request. currentexecutionfilepath ))); SB. append ( " <Br/> " ); SB. append ( String . Format ( " Obtain the root directory path of the current application: {0} " , Server. htmlencode (request. applicationpath ))); SB. append ( " <Br/> " ); SB. append ( String . Format ( " The Virtual Path of the current request: {0} " , Server. htmlencode (request. filepath ))); SB. append ( " <Br/> " ); SB. append ( String . Format ( " The Virtual Path of the current request: {0} " , Server. htmlencode (request. Path ))); SB. append ( " <Br/> " ); SB. append ( String . Format ( " Obtain the physical file system path of the root directory of the currently running application: {0} " , Server. htmlencode (request. physicalapplicationpath); sb. append ( " <Br/> " ); SB. append ( String . Format ( " Obtain the physical file system path corresponding to the requested URL: {0} " , Server. htmlencode (request. physicalapplicationpath ))); SB. append ( " <Br/> " ); Response. Write (sb. tostring ()); }

Output: Current Time: 11:03:49
The Virtual Path of the current request:/adirectory/sample/responsehtml. aspx
Obtain the root directory path of the current application:/adirectory
The Virtual Path of the current request:/adirectory/sample/responsehtml. aspx
The Virtual Path of the current request:/adirectory/sample/responsehtml. aspx
Obtain the physical file system path of the root directory of the currently running application: e: \ Visual Studio 2005 \
Obtain the physical file system path corresponding to the requested URL: e: \ Visual Studio 2005 \ adirectory \

In ASP. NET programming, requests are often used to obtain URL-related information.
The URL for the test is the http://www.test.com/testweb/default.aspx and the result is as follows:

Request. applicationpath:/testweb
Request. currentexecutionfilepath:/testweb/default. aspx
Request. filepath:/testweb/default. aspx
Request. Path:/testweb/default. aspx
Request. pathinfo:
Request. physicalapplicationpath: e: \ www \ testweb \
Request. physicalpath: e: \ www \ testweb \ default. aspx
Request. rawurl:/testweb/default. aspx
Request. url. absolutepath:/testweb/default. aspx
Request. url. absoluteuri: http://www.test.com/testweb/default.aspx
Request. url. HOST: www.test.com
Request. url. localpath:/testweb/default. aspx

When the URL contains parameters, you can use: httpcontext. Current. Request. url. pathandquery. tostring ()//

This page address: request. url;

Last page address:
Request. urlreferrer
Request. serverviables ["http_referer"]
Request. rawurl
Request. rawurl. queryandpath
System. Io. Path. getfilename (request. filepath. tostring ())

The following members are disclosed for the httprequest type.

Constructor
Description
Httprequest infrastructure. Initialize the httprequest object.
Top
Method
Description
The binaryread statement reads the specified number of bytes of the current input stream in binary format.
Equals determines whether the specified object is equal to the current object. (Inherited from object .)
Finalize allows the object to try to release resources and perform other cleanup operations before "Garbage Collection" recycles the object. (Inherited from object .)
Gethashcode is used as a hash function of a specific type. (Inherited from object .)
GetType: Get the type of the current instance. (Inherited from object .)
Mapimagecoordinates maps input image field form parameters to appropriate X and Y coordinate values.
Mappath is overloaded. Map the virtual path in the request URL to the physical path on the server for the current request.
Memberwiseclone creates a superficial copy of the current object. (Inherited from object .)
Saveas saves the HTTP request to the disk.
Returns the string of the current object. (Inherited from object .)
Validateinput verifies the set accessed through the cookies, form, and querystring attributes.
Top

Attribute
Description
Accepttypes obtains the string array of mime accept types supported by the client.
Anonymousid gets the user's anonymous identifier (if any ).
Applicationpath gets the root path of the virtual application of ASP. NET applications on the server.
Apprelativecurrentexecutionfilepath obtains the virtual path of the application root, and uses the waveform character (~) for the application root (~) Notation (for example, /Page. aspx "format) to make the path a relative path.
Browser gets or sets information about the browser functions of the client being requested.
Clientcertificate obtains the Client Security Certificate of the current request.
Contentencoding obtains or sets the character set of the entity body.
Contentlength specifies the length (in bytes) of the content sent by the client ).
Contenttype gets or sets the mime content type of the incoming request.
Cookies obtain the set of cookies sent by the client.
Currentexecutionfilepath gets the virtual path of the current request.
Filepath: Obtain the virtual path of the current request.
Files obtains the set of files uploaded by the client in multi-part MIME format.
Filter gets or sets the filter to be used when reading the current input stream.
Form to obtain a set of form variables.
Headers obtains the HTTP header set.
Httpmethod obtains the HTTP data transmission method (such as get, post, or head) used by the client ).
Inputstream obtains the content of the input HTTP entity body.
Isauthenticated gets a value indicating whether the request is verified.
Islocal gets a value indicating whether the request comes from a local computer.
Issecureconnection gets a value indicating whether the HTTP connection uses a secure socket (that is, https ).
Item obtains the specified object from the cookies, forms, querystring, or servervariables set.
Logonuseridentity obtains the windowsidentity type of the current user.
Params obtains a combination of querystring, form, servervariables, and cookies.
Path to obtain the virtual path of the current request.
Pathinfo gets the additional path information for resources with a URL extension.
Physicalapplicationpath gets the physical file system path of the root directory of the currently running server application.
Physicalpath obtains the physical file system path corresponding to the requested URL.
Querystring obtains the set of HTTP query string variables.
Rawurl gets the original URL of the current request.
Requesttype gets or sets the HTTP data transmission method (get or post) used by the client ).
Servervariables: a set of web server variables.
Totalbytes gets the number of bytes in the current input stream.
URL to obtain information about the URL of the current request.
Urlreferrer obtains the URL Information about the client's last request, which is linked to the current URL.
Useragent obtains the original user agent information of the client browser.
Userhostaddress: Obtain the IP host address of the remote client.
Userhostname: Obtain the DNS name of the remote client.
Userages obtains the sort string array of client language preferences.

1. Request. applicationpath-> current application directory
I have never touched JSP. If I have touched JSP, it will be very clear that applicationpath refers to the current application directory.
Corresponding -- for example, two web application domains on my server are mysite.com, one mapped to the directory mysite.com/1/ and the other to the http://MySite.com/2/
So mysite.com/1/ the applicationpath of the first application is the same as mysite.com/2/ applicationpath of the second application.

2. Request. filepath-> corresponds to the virtual directory of IIS
Such as URL http://MySite.com/1/index.html/pathinfo
Filepath =/1/index.html

3. Request. Path-> the virtual path of the current request
PATH is the concatenation of filepath and pathinfo. Example: URL http://MySite.com/1/index.html/pathinfo
Then Path =/1/index.html/pathinfo

4. Request. mappath (string URL)-> map the URL to a virtual directory on IIS
This directory is relative to the application root directory.
Compared with server. mappath, paths such as C:/are not included.
It can be understood as a relative path (the server. mappath in comparison is an absolute path)

5. server. mappath (string URL)-> map the URL to the physical path on the server.
For example, http://MySite.com/1/index.html suppose your application is in C:/IIS/mysite
C:/IIS/mysite/1/index.html

Requst. filepath: Obtain the virtual path of the current request. The filepath attribute does not contain the end of pathinfo. For example, if the URL http://www.contoso.com/virdir/page.html/tail,FilePath value is/virdir/page.html.

Request. Path: Obtain the virtual path of the current request. PATH is the concatenation of filepath and pathinfo. For example, the URL http://www.contoso.com/virdir/page.html/tail,Path is/virdir/page.html/tail.

The request. mappath method maps the specified virtual path to the physical path.
The followingCodeIn this example, the mappath method is used to convert a virtual path to a fully qualified physical path on the server. This example includes two parts:

. ASPX page ing path, Read File and display read operation results.

Uppercasefilterstream class, which changes all characters passed through it to uppercase.

The first part of the example shows how to use the mappath method to convert a virtual path to a fully qualified physical path. Then, the physical path is passed to the streamreader object, which contains the content of the file. Then, call the write method to display the file content on the page. The filter attribute is used to append a filter to the response stream. The response stream makes all text displayed on the page uppercase. Z

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.