The physical path of the website on the server disk: HttpRuntime.AppDomainAppPath
Virtual program path: HttpRuntime.AppDomainAppVirtualPath
Any methods related to Request/HttpContext.Current, etc., can only be used when there is a request context or page. That is, when there is no request context, HttpContext.Current is null. The methods mentioned above are always available.
The same is true for access to global Cache objects.
================================================== ================================
Example: Output asp.net website path.
private void responseHtml()
...{
System.Text.StringBuilder sb = new System.Text.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("Get 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("Get the physical file system path of the root directory of the currently executing application: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
sb.Append("<br />");
sb.Append(string.Format("Get 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: 2007-08-30 11:03:49
The virtual path of the current request: /aDirectory/Sample/responseHtml.aspx
Get 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
Get the physical file system path of the root directory of the currently executing application: E:Visual Studio 2005
Get the physical file system path corresponding to the requested URL: E:Visual Studio 2005\aDirectory
In ASP.NET programming, it is often necessary to use Request to obtain information about the URL.
The test url address is http://www.test.com/testweb/default.aspx , and the results are 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:WWWtestweb
Request.PhysicalPath: E:WWWtestwebdefault.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
You can use this when there are parameters in the url:
HttpContext.Current.Request.Url.PathAndQuery.ToString()//
The address of this page: Request.URL;
Previous page address:
Request.UrlReferrer
Request.ServerViables["http_referer"]
Request.RawUrl
Request.RawUrl.QueryAndPath
System.IO.Path.GetFileName(Request.FilePath.ToString())
The HttpRequest type exposes the following members.
Constructor name description
HttpRequest infrastructure. Initialize the HttpRequest object.
Top method name description
BinaryRead Performs a binary read of the specified number of bytes from the current input stream.
Equals determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize allows an Object to attempt to release resources and perform other cleanup operations before Garbage Collection reclaims the Object. (Inherited from Object.)
GetHashCode is used as a hash function for a specific type. (Inherited from Object.)
GetType Gets the Type of the current instance. (Inherited from Object.)
MapImageCoordinates maps incoming image field form parameters to appropriate x and y coordinate values.
MapPath has been reloaded. Maps the virtual path in the requested URL to a physical path on the server for the current request.
MemberwiseClone creates a shallow copy of the current Object. (Inherited from Object.)
SaveAs Saves the HTTP request to disk.
ToString returns a String representing the current Object. (Inherited from Object.)
ValidateInput validates collections accessed through the Cookies, Form, and QueryString properties.
Top attribute name description
AcceptTypes Gets a string array of MIME accept types supported by the client.
AnonymousID Gets the anonymous identifier for this user, if one exists.
ApplicationPath Gets the virtual application root path of the ASP.NET application on the server.
AppRelativeCurrentExecutionFilePath Gets the virtual path to the application root and makes the path relative by using tilde (~) notation for the application root (for example, in the form "~/page.aspx").
Browser Gets or sets information about the browser capabilities of the requesting client.
ClientCertificate Gets the client security certificate for the current request.
ContentEncoding Gets or sets the character set of the entity body.
ContentLength specifies the length of the content sent by the client, in bytes.
ContentType Gets or sets the MIME content type of the incoming request.
Cookies Gets the collection of cookies sent by the client.
CurrentExecutionFilePath Gets the virtual path of the current request.
FilePath Gets the virtual path of the current request.
Files Gets a collection of files uploaded by the client in multipart MIME format.
Filter Gets or sets the filter to use when reading the current input stream.
Form Gets the form variable collection.
Headers Gets the HTTP header collection.
HttpMethod Gets the HTTP data transfer method used by the client (such as GET, POST, or HEAD).
InputStream Gets the contents of the incoming HTTP entity body.
IsAuthenticated Gets a value indicating whether the request was authenticated.
IsLocal Gets a value indicating whether the request came from the local computer.
IsSecureConnection Gets a value that indicates whether the HTTP connection uses secure sockets (that is, HTTPS).
Item Gets the specified object from the Cookies, Form, QueryString, or ServerVariables collection.
LogonUserIdentity Gets the WindowsIdentity type of the current user.
Params Gets the combined collection of QueryString, Form, ServerVariables, and Cookies items.
Path gets the virtual path of the current request.
PathInfo Gets additional path information for a resource with a URL extension.
PhysicalApplicationPath Gets the physical file system path to the root directory of the currently executing server application.
PhysicalPath Gets the physical file system path corresponding to the requested URL.
QueryString Gets the collection 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 Gets a collection of Web server variables.
TotalBytes Gets the number of bytes in the current input stream.
Url Gets information about the currently requested URL.
UrlReferrer Gets information about the last URL requested by the client, which linked to the current URL.
UserAgent Gets the client browser's original user agent information.
UserHostAddress Gets the IP host address of the remote client.
UserHostName Gets the DNS name of the remote client.
UserLanguages Gets a sorted string array of client language preferences.
1.Request.ApplicationPath->The directory of the current application. The author has not come into contact with jsp. If you have come into contact with jsp, it will be very clear. ApplicationPath refers to the directory corresponding to the current application (application)-for example, there is one on my server. Both web application domain names are MySite.com, one maps to the directory MySite.com/1/ and the other alludes to http://MySite.com/2/
Then MySite.com/1/ is the ApplicationPath of the first application. Similarly, MySite.com/2/ is the 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->Virtual path of current request
Path is the concatenation of the FilePath and PathInfo tails. For 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 root directory of the application. Compared with Server.MapPath, it is understandable that it will not contain a path like c:/ is a relative path (the compared Server.MapPath is an absolute path)
5.Server.MapPath(string url)->Map the url to a physical path on the server. For example, http://MySite.com/1/index.html assuming your application is in c:/iis/MySite, then it is c :/iis/MySite/1/index.html
Requst.FilePath gets the virtual path of the current request. The FilePath property does not contain the PathInfo trailer. For example, for the URL http://www.contoso.com/virdir/page.html/tail , the FilePath value is /virdir/page.html.
================================================== ================================================== ===========================
Request.Path gets the virtual path of the current request. Path is the concatenation of the FilePath and PathInfo tails. For example, for the URL http://www.contoso.com/virdir/page.html/tail , the Path is /virdir/page.html/tail.
================================================== ================================================== ===========================
The Request.MapPath method maps the specified virtual path to a physical path.
The following code example uses the MapPath method to convert a virtual path to a fully qualified physical path on the server. This example consists of two parts:
The .aspx page maps the path, reads the file, and displays the results of the read operation.
UpperCaseFilterStream class that 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. Afterwards, this physical path is passed to the StreamReader object, which contains the contents of the file. Then, call the Write method to display the contents of the file on the page. The Filter property is used to attach a filter to the response flow that causes the text displayed on the page to be in all caps.
-