您的位置:首页 > 理论基础 > 计算机网络

TransferResult处理中用MvcHttpHandler在mvc3和mvc5区别

2015-08-21 16:03 591 查看


“System.InvalidOperationException”类型的异常在 System.Web.dll 中发生,但未在用户代码中进行处理

其他信息: 只能在引发“HttpApplication.AcquireRequestState”之前调用“HttpContext.SetSessionStateBehavior”。



/// <summary>
/// Transfers execution to the supplied url.
/// </summary>
public class TransferResult : ActionResult
{
public string Url { get; private set; }

public TransferResult(string url)
{
this.Url = url;
}

public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");

var httpContext = HttpContext.Current;

// MVC 3+ running on IIS 7+
if (HttpRuntime.UsingIntegratedPipeline)
{
httpContext.Server.TransferRequest(this.Url, true);
}
else
{
// Pre MVC 3
httpContext.RewritePath(this.Url, false);

IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(httpContext);
}
}
}


重点是下面的:

// MVC3+ running on IIS 7+

if (HttpRuntime.UsingIntegratedPipeline)

{

httpContext.Server.TransferRequest(this.Url, true);

}

else

{

// Pre MVC 3

httpContext.RewritePath(this.Url, false);

IHttpHandler httpHandler = new MvcHttpHandler();

httpHandler.ProcessRequest(httpContext);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: