• Session超时问题(AOP 过滤器)


    public class TimeoutAttribute : ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                HttpContextBase context = filterContext.HttpContext;
                HttpResponseBase response = filterContext.HttpContext.Response;
                HttpRequestBase request = filterContext.HttpContext.Request;
                if (context.Session["User"] == null)
                {
                    if (request.IsAjaxRequest())
                        response.Status = "401 Session Timeout";
                    else
                        response.Redirect("/Home/Login");//返回登录页
                    filterContext.Result = new HttpUnauthorizedResult();//这一行保证不再执行Action的代码
                    response.End();//必须加上这句,否则返回前台status始终是200
                    return;
                }
                base.OnActionExecuting(filterContext);
            }
        }
    前台:
    error:function(a,b,c){
    if(c.statusText=="Session Timeout"){
                    location="/home/login";
                }

    }

     本文参考 I鱿鱼的博客。。。。。

  • 相关阅读:
    OSCache报错error while trying to flush writer
    html 输入框验证
    Struts2 一张图片引发的bug
    Html 小插件10 即时新闻
    String
    内部类
    多态
    抽象&接口
    继承
    封装
  • 原文地址:https://www.cnblogs.com/gaocong/p/4767148.html
Copyright © 2020-2023  润新知