我有OnActionExecuting
ActionFilter
其中我已检查用户会话是否已过期,并且在会话过期的情况下,用户必须重定向到登录页面。服务器在发送http头之后无法设置状态
CompressFilterAttribute.cs文件具有代码,如下所示:
public override void OnActionExecuting(ActionExecutingContext FilterContext)
{
if (((((System.Web.Mvc.ControllerContext)(FilterContext)).HttpContext).Request).IsAuthenticated)
GZipEncodePage(); //Function to check Session Expiration Time
var action = (string)FilterContext.RouteData.Values["action"];
if (!FilterContext.HttpContext.User.Identity.IsAuthenticated &&
action != "Index" &&
action != "FindStoreNameByText" &&
action.ToLower() != "sessiontimeout" &&
action.ToLower() != "logout")
{
string UrlSucesso = "/Home";
string UrlRedirecionar = string.Format("?ReturnUrl={0}", UrlSucesso);
string UrlLogin = FormsAuthentication.LoginUrl + UrlRedirecionar;
FilterContext.HttpContext.Response.Redirect(UrlSucesso, true);
}
}
CustomErrorHandleAttribute.cs文件具有代码,如下所示:
public override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
// Rest logic
}
在CustomErrorHandleAttribute.cs文件我收到错误 - >服务器无法设置状态后http头hav e已发送
请帮我。
可能重复[服务器无法设置状态后HTTP头已发送IIS7.5](http://stackoverflow.com/questions/2383169/server-cannot-set-status-after-http-headers-have-been-sent-iis7-5) – drzaus