【问题标题】:MVC3 Application Inside Webforms Application Routing is throwing a HttpContext.SetSessionStateBehavior Error in IIS7.5Webforms 应用程序路由中的 MVC3 应用程序在 IIS7.5 中引发 HttpContext.SetSessionStateBehavior 错误
【发布时间】:2012-05-17 16:38:41
【问题描述】:

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

在 VS 2010 调试 (Cassini) 中一切正常,但是当我部署到 IIS7.5 时

我收到以下错误:

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

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

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);
}

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

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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net-mvc-3 iis-7.5 webforms


    【解决方案1】:

    我们遇到了类似的问题。 MVC2 及以上版本的 MVCHttpHandler 有变化。

    您需要将其更改为使用httpContext.Server.TransferRequest

    试试下面的 sn-p:

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

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2022-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多