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