5

I'm running a mixed MVC Application inside a sub folder of a web forms application.

Everything worked great in VS 2010 debug (Cassini) but when I deployed to IIS7.5

I got the following error:

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

It errors on the last line (httpHandler.ProcessRequest(HttpContext.Current);) in the default.aspx file of the MVC application sub folder.

public void Page_Load(object sender, System.EventArgs e)
{
    string pathToRewriteTo = Request.Path.ToLowerInvariant().Replace("default.aspx", "Home/Index");

    HttpContext.Current.RewritePath(pathToRewriteTo, false);

    IHttpHandler httpHandler = new MvcHttpHandler();

    httpHandler.ProcessRequest(HttpContext.Current);
}

However if I manually navigate to Home/Index from the MVC root folder I can see my application fine from there.

I've looked up the error being thrown and I only find answers dealing with server transfers and not MVC routes.

I have also already checked my IIS7.5 configuration for the route handling module, Application pool running in integrated mode, etc.

Any help would be appreciated.

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
Tonicia Kelly
  • 51
  • 1
  • 4

1 Answers1

8

We faced a similar issue. There are changes to MVCHttpHandler in MVC2 and above.

You need to change it to use httpContext.Server.TransferRequest.

Try the below snippet:

var httpContext = HttpContext.Current;
httpContext.Server.TransferRequest(Url, true); // change to false to pass query string parameters if you have already processed them
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
csharpnewbie
  • 789
  • 2
  • 12
  • 33