Getting relative root in Global.Asax

asp.net, c#, global, global-variables

Solution

In order to get a relative path within application_start use the following:

 protected void Application_Start(object sender, EventArgs e)
 {
     string path = Server.MapPath("/");
 }

Problem

I am trying to store the physical root and relative root of my application in memory at application startup. I did the physical path like so: ``` //Get the physical root and store it Global.ApplicationPhysicalPath = Request.PhysicalApplicationPath; ``` But I cannot get the relative path. I have the following code that works, but it requires it to be put in a `page` object: ``` Global.ApplicationRelativePath = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") + Page.ResolveUrl("~/"); ``` Thanks

Original source