Configuration of. NET absolute paths

Source: Internet
Author: User
Tags httpcontext

Sometimes because a Web site is configured with IIS, there are some global references that have path problems that cannot be referenced. Let's talk today about the configuration of the absolute path to the global reference, for example, because of the virtual path of the IIS configuration, some Css,js references are not found, or some of the custom jumps appear 404. These questions are simple and very basic.

We can define a BasePage class, put some page public reference, hint information inside, so that each page as long as the inheritance of this class, you can directly use the method in the BasePage (object-oriented one of the three main features: Inherit all know! )。 A string that defines an absolute path first

    <summary>///    define absolute path///    </summary> public    string applicationpath = "";

Then initialize. Note that the derived class used here implements the method of the base class. Use override to override this feature, using the base keyword to inherit the method of the base class.

    <summary>///initialization function///</summary>//    <param name= "E" ></param>    protected override void OnInit (EventArgs e)    {        base. OnInit (e);        InitApplication ();    }

Finally, an absolute path assignment is implemented

<summary>
Initialize Request path
</summary>
public void InitApplication ()
{
#region Definition Applicationpage
This. Applicationpath = HttpContext.Current.Request.ApplicationPath = = "/"? "": HttpContext.Current.Request.ApplicationPath + ";
#endregion
}

At this point applicationpath is the root name of the site.

Configuration of. NET absolute paths

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.