The HttpContext.Current.Request.ApplicationPath property represents a virtual directory in IIS or WebDev.WebServer.
HttpContext.Current.Request.ApplicationPath evaluates to "/virtualdirectory"
This can be used in conjunction with VirtualPathUtility to make the path root relative:
VirtualPathUtility.ToAbsolute("~/images/cat.jpg", HttpContext.Current.Request.ApplicationPath) // (this evaluates to "/virtualdirectory/images/cat.jpg")
In IIS6 and WebDev.WebServer, the Request object is available in global.asax.cs , but IIS7 complains that it is "not available in the current context." Therefore, the second line of code above works, but not in IIS7.
The problem is that I need to access the virtual directroy name inside global.asax.cs . I need him to build several paths that are used in dynamically generated CSS. Is there an alternative way to access this value?
Edit: This is the error you get in IIS 7 to call HttpContext.Current.Request in global.asax.cs in Application_Start:
HttpException (0x80004005): Request is not available in this context] System.Web.HttpContext.get_Request() +8789264
Simon_Weaver
source share