Asp. NET ways to get paths

Source: Internet
Author: User
Tags httpcontext hosting

HttpContext.Current.Request.PhysicalPath; Gets the full physical path of the current page. For example,

F:\XFU. Nsqs\project\website\default.aspx
HttpContext.Current.Request.PhysicalApplicationPath; Gets the physical path of the current program running

such as F:\XFU. Nsqs\project\website\
HttpContext.Current.Server.MapPath (@ "\"); This is the MapPath in the page. Same usage

Httpruntime.appdomainapppath//This is new found, very useful.

Another is used to handle calling DLL files in ASP. dll files if you want to know the working directory of the current Web site can be

To use
System.AppDomain.CurrentDomain.BaseDirectory

The physical path of the Web site on the server disk: Httpruntime.appdomainapppath
Virtual Program path: Httpruntime.appdomainappvirtualpath

HttpContext.Current.Request.ApplicationPath Virtual Application root Path
HttpContext.Current.Server.MapPath (".") The current absolute path
The HttpContext.Current.Server.MapPath (HttpContext.Current.Request.ApplicationPath) system

root directory

Sb. Append (String. Format ("Virtual path of the current request: {0}", Server.HTMLEncode

(Request.currentexecutionfilepath)));
Sb. Append (String. Format ("Get the root directory path of the current application: {0}",

Server.HTMLEncode (Request.applicationpath));
Sb. Append (String. Format ("Virtual path of the current request: {0}", Server.HTMLEncode

(Request.filepath)));
Sb. Append (String. Format ("Virtual path of the current request: {0}", Server.HTMLEncode

(Request.path)));
Sb. Append (String. Format ("Gets the physical file system path of the root of the currently executing application:

{0} ", Server.HTMLEncode (Request.physicalapplicationpath)));
Sb. Append (String. Format ("Get the physical file system path corresponding to the requested URL: {0}",

Server.HTMLEncode (Request.physicalapplicationpath));

Virtual path of the current request:/adirectory/sample/responsehtml.aspx
Gets the root directory path of the current application:/adirectory
Virtual path of the current request:/adirectory/sample/responsehtml.aspx
Virtual path of the current request:/adirectory/sample/responsehtml.aspx
Gets the physical file system path of the root directory of the currently executing application: E:\Visual Studio 2005\
Gets the physical file system path that corresponds to the requested URL: E:\Visual Studio 2005\\adirectory\

Sb. Append (String. Format ("Get the full absolute path of the project: {0}",

System.AppDomain.CurrentDomain.BaseDirectory.ToString ()));
This property is available only after an attempt is made to load an assembly into this domain
Sb. Append (String. Format ("Gets the project, which is used by the Assembly resolver to probe dynamically created

Assembly: {0} ", System.AppDomain.CurrentDomain.DynamicDirectory));
Sb. Append (String. Format ("Gets the physical path to the application directory on the disk. : {0} ",

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
Sb. Append (String. Format ("Get the virtual root path of the application: {0}",

System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
Sb. Append (String. Format ("Gets the name of the site. : {0} ",

System.Web.Hosting.HostingEnvironment.SiteName));
Sb. Append (String. Format ("Gets the virtual path provider for this application. : {0} ",

System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
Sb. Append (String. Format ("returns the physical file corresponding to the specified virtual path on the WEB server

Path. : {0} ", Server.MapPath (" sss.aspx "));

Asp. NET ways to get paths

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.