从MVC2升级到MVC3会导致异常。见说明

时间:2014-02-25 17:17:52

标签: model-view-controller upgrade

我已经查看了许多可能重复的帖子,但没有运气正确实现它们。我得到的例外是:

'HttpContext.SetSessionStateBehavior'只能在引发'HttpApplication.AcquireRequestState'事件之前调用。

这是我的代码:

public void Page_Load(object sender, System.EventArgs e)
{
    string originalPath = Request.Path;
    HttpContext.Current.RewritePath(Request.ApplicationPath, false);
    IHttpHandler httpHandler = new MvcHttpHandler();
    httpHandler.ProcessRequest(HttpContext.Current);
    HttpContext.Current.RewritePath(originalPath, false);
}

1 个答案:

答案 0 :(得分:0)

修正了:

public void Page_Load(object sender, System.EventArgs e)
{
    string originalPath = Request.Path;
    HttpContext.Current.RewritePath(Request.ApplicationPath, false);
    IHttpHandler httpHandler = new MvcHttpHandler();
    HttpContext.Current.Server.TransferRequest(Request.ApplicationPath);
    HttpContext.Current.RewritePath(originalPath, false);
}