[Net] obtaining physical and virtual paths in ASP. NET

Source: Internet
Author: User
Obtain physical and virtual paths in ASP. NET

// Request. currentexecutionfilepath; the virtual path of the current request is in this format:/virtual directory name/admin/index. aspx
// Request. applicationpath // obtain the root path of the virtual application of ASP. NET applications on the server. /Virtual directory name (Application name)

The above are the file paths in the virtual directory, that is, the paths in IIS. To obtain a real physical path, you must add the following to the above path:
Server. mappath (request. applicationpath + "splconfig/classmap. xml") // This may cause a bug.

This is the best practice.
String m_applicationpath = request. applicationpath;
If (this. m_applicationpath = "")
This. m_applicationpath = "/";
If (! This. m_applicationpath.endswith ("/"))
This. m_applicationpath + = "/"; // first judge/
Server. mappath (m_applicationpath + "splconfig/classmap. xml ")

2005 new URL access method
// This. Request. currentexecutionfilepath; // the path in the virtual busy state of the current request
// This. Request. filepath; // path in the virtual directory
// This. Request. physicalpath; // physical path of the current request
// This. Request. physicalapplicationpath; // physical path of the application
// This. Request. url. absoluteuri; // All URLs

Request. rawurl get URL with variable request. urlreferrer get URL without variable

How to refresh this page:
This. response. Redirect (this. Request. url. absoluteuri, true );

This. response. Redirect (this. Request. url. tostring ());

Refresh custom methods

This. response. Redirect (this. Request. currentexecutionfilepath + "? Depid = "+ this. hdepid. value. tostring ());

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.