8
In the code below, when I try to call the Mappath function inside Global.asax, an error occurs at runtime with the following error message:
System.Web.Httpexception (0 80004005): Request is not available in this context.
The defective code is:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
string path = HttpContext.Server.MapPath("~/assets/all.js")
// ... code
}
How to use a Mappath function in Global.asax?
Note: The one previously used
HttpContext.Current
is no longer available onApplication_Start
in IIS version 7. If the application is hosted in a previous version or mode classic the context will be available. But of course, I do not recommend this dependency :)– talles