I have setup error handling as described here: How can I properly handle 404 in ASP.NET MVC?
When the errorController.Execute method is called, I get an InvalidOperationException: The SessionStateTempDataProvider requires SessionState to be enabled.
My session state mode is set to InProc, but I'm not using it so I also tried turning it off as described here: How can I disable session state in ASP.NET MVC? The code is executed, but I still get the error.
This is happening locally using the Visual Studio built-in web browser.
Is there a way to fix this?
Best Answer
This problem can be fixed by overriding the ExecuteCore method in your ErrorController. Apparently some kinds of errors (e.g. forbidden file access) don't fully populate the HttpContext that's available to the error handler; in particular Context.Session == null, which causes the ExecuteCore method to choke trying to determine if there's any TempData that needs to be saved/loaded.
I decided I can live without TempData in my error controller; here is my implementation.