asp.net-mvc-3 – MVC3应用程序内部Webforms应用程序路由在IIS7.5中抛出HttpContext.SetSessionStateBehavior错误

我正在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配置,以集成模式运行的应用程序池等.

任何帮助,将不胜感激.

解决方法

我们遇到了类似的问题. 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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....