我正在使用以下ActionFilter来检查会话变量是否已经丢失,如果是这样,他们被重定向到'选择仓库代码屏幕'...只要用户担心它工作正常......但是,每次通过ActionFilter重定向时,ELMAH都会报告错误(请参阅下面的代码)。ActionFilter - 发送HTTP头后无法重定向
P.S.这个ActionFilter属性然后放在一个基础控制器上,所有其他控制器继承它。
P.P.S.没有其他的重定向正在进行......这个动作过滤器在他们试图执行的动作之前发射......我不能为我的生活找出为什么我不断收到这个错误。
public class HasWarehouseCodeExpired : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Controller controller = filterContext.Controller as Controller;
if (controller != null)
{
if (SessionHelper.WarehouseCode == null)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "logon", action = "displaywarehouseselection", area = string.Empty }));
}
}
base.OnActionExecuting(filterContext);
}
}
错误:
System.Web.HttpException (0x80004005): Cannot redirect after HTTP headers have been sent. at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) at System.Web.HttpResponseWrapper.Redirect(String url, Boolean endResponse) at System.Web.Mvc.RedirectToRouteResult.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)