7

I have a custom IHttpHandler that calls MvcHttpHandler implemented as described in this answer.

It worked well in asp.net MVC2, but after I migrate the code to MVC4 with IISExpress 7.5, I start getting InvalidOperationException on the line:

httpHandler.ProcessRequest(HttpContext.Current);

with message:

'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised.

ASP.NET Development Server does not make any problems.

Does anyone know what's going on here, and how to solve it?

Community
  • 1
  • 1
ni5ni6
  • 453
  • 6
  • 13

1 Answers1

7

I believe you need to use httpContext.Server.TransferRequest with the MVC update.

See this question: MVC3 Application Inside Webforms Application Routing is throwing a HttpContext.SetSessionStateBehavior Error in IIS7.5

Community
  • 1
  • 1
Ryan O'Neill
  • 1,710
  • 2
  • 13
  • 24
  • I tried that one, but it doesn't work. I believe it's because there is no place where I tell system to use MvcHandler to process the requested path. – ni5ni6 Jun 12 '12 at 14:46
  • I replaced these two lines: IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); With: HttpContext.Current.Server.TransferRequest(Request.ApplicationPath); And it worked great! – puddinman13 Nov 27 '13 at 17:47
  • I'm getting the same errors after upgrading our application from MVC 2 to MVC 5. Unfortunately, there is a place where `Server.TransferRequest` generates an error and cannot be used a replacement. Are there other options? My question: http://stackoverflow.com/questions/26533724/execute-multiple-controller-actions-in-one-call-with-mvc-net-5 – Zarepheth Oct 23 '14 at 18:20