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

Model view controller 从MVC2升级到MVC3会导致异常。见说明,model-view-controller,upgrade,Model View Controller,Upgrade,我看了很多文章,寻找可能的重复,但没有成功地正确实现它们。我得到的例外是: “HttpContext.SetSessionStateBehavior”只能在引发“HttpApplication.AcquisiteRequestState”事件之前调用 这是我的代码: public void Page_Load(object sender, System.EventArgs e) { string originalPath = Request.Path; HttpContext.C

我看了很多文章,寻找可能的重复,但没有成功地正确实现它们。我得到的例外是:

“HttpContext.SetSessionStateBehavior”只能在引发“HttpApplication.AcquisiteRequestState”事件之前调用

这是我的代码:

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);
}
修正了它:

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