Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request object in Application_Start event

Tags:

c#

iis-7

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

like image 351
desi Avatar asked Apr 21 '11 21:04

desi


1 Answers

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.

like image 121
Jess Avatar answered Oct 20 '22 01:10

Jess