Asp.net project path Acquisition Method

Source: Internet
Author: User

I have obtained the project path through the experiment in the following ways:

Obtain the complete absolute path of the project.

String Path = system. appdomain. currentdomain. basedirectory. tostring ();

String Path = server. mappath (".");// This "." can be changed to another folder name in the project file.

 

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 current applicationProgramRoot directory path of: {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: 10:26:47
The Virtual Path of the current request:/test/gauge. aspx
Obtain the root directory path of the current application:/test
The Virtual Path of the current request:/test/gauge. aspx
The Virtual Path of the current request:/test/gauge. aspx
Obtain the physical file system path of the root directory of the currently running application: D: \ Asp.net test project \ test \
Obtain the path of the physical file system corresponding to the requested URL: D: \ Asp.net test project \ test \

If you have other methods, thank you for providing them and sharing them.

Everyone learns and communicates with each other

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.