. NET Common application root path

Source: Internet
Author: User

I did not find a suitable one on the Internet. I wrote one on my own and tested it to meet various situations.

Code # Region generate the absolute path of the URL application (http: // localhost: 8080/website)
String abspath = system. Web. httpcontext. Current. Request. url. absolutepath;
Abspath = abspath. substring (system. Web. httpcontext. Current. Request. applicationpath. Length );
This. _ apppath = system. Web. httpcontext. Current. Request. url. absoluteuri. Replace (abspath ,"");
This. _ apppath. trimend ('/');
# Endregion

# Region generate the physical path of the application hard disk (D: \ wwwroot \ website)
This. _ physicalpath = system. Web. httpcontext. Current. Request. servervariables ["appl_physical_path"]. tostring (). trimend ('\\');
# Endregion

# Region generate the absolute path of the URL application skin (http: // localhost: 8080/website/app_themes/green)
System. Web. configuration. pagessection _ PS = (system. Web. configuration. pagessection) system. configuration. configurationmanager. getsection ("system. Web/pages ");
This. _ themename = _ PS. theme;
This. _ fullthemepath = string. Format ("{0}/app_themes/{1}", this. _ apppath, _ PS. Theme). trimend ('/');
# Endregion

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.