[ASP .NET] How to access Request data when HttpContext.Current.Request is unavailable

What happened if you need to access the HttpRequest object whitin the event Application_Start of an ASP .NET Web Application ?

Response: you end up with an exception.

Someone might observe that such event is not a valid place for a task like that, but sometimes things are simply different from those that appear at first sight.

So, if you want to get for example the virtual path or the physical path of a web application before the HttpRequest object is constructed  this is a valid solution:

HttpRuntime.AppDomainAppVirtualPath;
HttpRuntime.AppDomainAppPath;

Simply use HttpRuntime instead of HttpContext.Current.Request!

Technorati Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *