Two common paths in ASP. NET

Source: Internet
Author: User

During. NET programming, it is often difficult to use relative paths because of directory structure problems, instead of absolute URLs of applications. But this will involve the application name and port. I probably wrote a method to get the URL path.

 

Absolute URL path

# Region generate the absolute path of the URL Application
String abspath = system. Web. httpcontext. Current. Request. url. absolutepath;
Abspath = abspath. substring (system. Web. httpcontext. Current. Request. applicationpath. Length );
String asburl = system. Web. httpcontext. Current. Request. url. absoluteuri;
This. _ apppath = asburl. substring (0, asburl. indexof (abspath ));
This. _ apppath. trimend ('/');
# Endregion

Hard Disk Physical path and skin path

# Region generate the physical path of the application Hard Disk
This. _ physicalpath = system. Web. httpcontext. Current. Request. servervariables ["appl_physical_path"]. tostring (). trimend ('\\');
# Endregion

# Region generate the absolute path of the skin of the URL Application
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

 

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.