We currently use this line of code to get the current applications url in the Application_Start event.
string sApplicationURL = HttpContext.Current.Request.Url.Scheme + "://"
+ HttpContext.Current.Request.Url.Authority
+ HttpContext.Current.Request.ApplicationPath;
I just recently found out that in IIS7.0 the Request object is no longer available when the Application_Start event is fired.
Is there another way to get the current applications url without using the Request object?
Thanks
Have a look at this: http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
In summary, the error occurs because the Request context is not longer available to the Application_Start event. This blog states two choices to deal with this error:
1) Change your code to work w/o Request, or 2) Modify your application to run in Classic Mode (not recommended).
To get the ApplicationPath, use HttpRuntime.AppDomainAppVirtualPath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With