Asp.net url path Retrieval Method

Source: Internet
Author: User

The solution mainly relies on httpcontext objects, such

Httpcontext. current. request. physicalpath; // obtain the complete physical path of the current page. For example, f: xfu. nsqsprojectwebsitedefault. asp tutorial x
Httpcontext. current. request. physicalapplicationpath; // obtain the physical path of the current program running, such as f: xfu. nsqsprojectwebsite
Httpcontext. current. server. mappath (@ ""); this is the mappath in the page.

Httpruntime. appdomainapppath // This is a newly discovered and useful method.

Another method is to call the dll file in the asp.net tutorial. If you want to know the working directory of the current web site, you can use
System. appdomain. currentdomain. basedirectory


Three simple methods

When Xi asp.net uploads a file, it finds that there are three methods to obtain the physical path of the current web program directory:

Method 1:

String spath = system. io. path. getdirectoryname (page. request. physicalpath)

Method 2:

String spath = system. web. httpcontext. current. request. mappath ("images /")

// ("Images/") is any directory under the current virtual directory

Method 3:

String spath = page. server. mappath ("images/"); // ("images/") is any directory in the current virtual directory

Also: get the file name in the full path

String sfile = system. io. path. getfilename (sfile );

 

// Obtain the complete path of the current process, including the file name (process name ).

String str = this. gettype (). assembly. location;

Result: x: xxxxxxxxx.exe (.exefile)

// Obtain the complete path of the new process component and associate it with the active process, including the file name (process name ).

String str = system. diagnostics. process. getcurrentprocess (). mainmodule. filename;

 

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.