Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 Application Inside Webforms Application Routing is throwing a HttpContext.SetSessionStateBehavior Error in IIS7.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.

like image 534
Tonicia Kelly Avatar asked May 17 '12 16:05

Tonicia Kelly


1 Answers

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
like image 199
csharpnewbie Avatar answered Nov 15 '22 06:11

csharpnewbie