In my MVC web application, I check Request.IsLocal to check if the application is running on my machine - if so, I set a global static variable that tells the rest of my application that I am in 'Debug mode'.
The problem is that I do not know when to do this check.
I tried to do this in the global.asax.cs file in the Application_Start () section, for example:
protected void Application_Start()
{
if (Request.IsLocal)
isDebug = true;
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
}
The problem is that the Request object has not yet been initialized. I get an HttpException that says
Incoming request does not match any route
So my question is, when is the Request object initialized, and is there some kind of event that I could handle to trigger this check after the Request object is ready?