MVC3 Application Inside Webforms Application Routing throws HttpContext.SetSessionStateBehavior error in IIS7.5

I am running a mixed MVC application inside a subfolder of a web forms application.

Everything worked fine in VS 2010 debugging (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. 

These are errors in the last line ( httpHandler.ProcessRequest(HttpContext.Current); ) in the default.aspx file of the MVC application subdirectory.

 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 from there.

I was looking for an error, and I only find answers to server transfers, not MVC routes.

I also already checked the IIS7.5 configuration for the route processing module, application pool running in integrated mode, etc.

Any help would be appreciated.

+5
source share
1 answer

We faced a similar problem. Changes in MVCHttpHandler in MVC2 and higher.

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

Try the snippet below:

 var httpContext = HttpContext.Current; httpContext.Server.TransferRequest(Url, true); // change to false to pass query string parameters if you have already processed them 
+8
source

All Articles