I am developing an application via .Net framework 4.5 and Asp.net MVC5. I try to access to Request object in Application_Error but I get "Request is not available in this context" error.
Here is my code:
protected void Application_Error(object sender, EventArgs e)
{
var httpContext = ((MvcApplication)sender).Context;
var req1 = httpContext.Request;
also I tried this
var req2= HttpContext.Current.Request;
while the second code is working fine in Asp.net MVC3 projects.
Any Idea?
Requestobject do you expect to be able to retrieve? The HttpContext might have been disposed long time ago.Application_Startthere's no concept of an HttpContext. You shouldn't be throwing any errors in yourApplication_Start. The best you could do in this case is log the error. But you cannot display anything to the user simply because at this stage there's no concept of an HttpContext.