WebC应用程序路由中的MVC3应用程序在IIS7.5中抛出HttpContext.SetSessionStateBehavior错误

Ton*_*lly 5 webforms iis-7.5 asp.net-mvc-3

我正在Web表单应用程序的子文件夹中运行混合MVC应用程序.

在VS 2010调试(Cassini)中,一切都运行良好,但是当我部署到IIS7.5时

我收到以下错误:

'HttpContext.SetSessionStateBehavior' can only be invoked before
  'HttpApplication.AcquireRequestState' event is raised.
Run Code Online (Sandbox Code Playgroud)

它在MVC应用程序子文件夹httpHandler.ProcessRequest(HttpContext.Current);default.aspx文件中的最后一行()上出错.

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);
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我从MVC根文件夹手动导航到Home/Index,我可以从那里看到我的应用程序正常.

我查找了抛出的错误,我只找到处理服务器传输而不是MVC路由的答案.

我还检查IIS7.5了路由处理模块的配置,以集成模式运行的应用程序池等.

任何帮助,将不胜感激.

csh*_*bie 8

我们遇到了类似的问题.MVC2及更高版本中的MVCHttpHandler发生了变化.

您需要更改它才能使用httpContext.Server.TransferRequest.

试试下面的代码:

var httpContext = HttpContext.Current;
httpContext.Server.TransferRequest(Url, true); // change to false to pass query string parameters if you have already processed them
Run Code Online (Sandbox Code Playgroud)