zoukankan      html  css  js  c++  java
  • MVC Session记录错误POST登录次数(不针对某个用户)

    Session的IsNewSession可以判断这次请求是否第一次访问, 所以如果是第一次访问而且cookie里包含ASP.NET_SessionId,那么可以判断Session已经过期

    因此我们可以写一个如下的一个Filter加在需要判断过期的Action上,当然如果所有Action都需要处理我们可以让所有的Controller集成一个BaseController,在BaseController的OnActionExecuting方法里做, 请参考如下代码

    public void OnActionExecuting(ActionExecutingContext filterContext)
            {
                //以下记录错误登录次数,如果错误登录次数太大,跳转到验证码登录
                if (filterContext.HttpContext.Request.FilePath == "/Account/LogOn")
                {
                    HttpContextBase ctx = filterContext.HttpContext;
                    if (ctx.Session != null)
                    {
                        if (ctx.Session.IsNewSession)
                        {
                            int logOnErrorTimes = 0;
                            ctx.Session.Add(ctx.Session.SessionID, logOnErrorTimes);
                        }
                        else
                        {
                            int logOnErrorTimes = Convert.ToInt32(ctx.Session[ctx.Session.SessionID]) + 1;
                            ctx.Session.Remove(ctx.Session.SessionID);
                            ctx.Session.Add(ctx.Session.SessionID, logOnErrorTimes);
                            ctx.Session.Timeout = 1440;
                        }
                    }
                }

  • 相关阅读:
    狗蛋带仨妞【Beta】Scrum meeting 1
    实验九 团队作业5:团队项目编码与Alpha冲刺
    狗蛋带仨妞【Alpha】Scrum meeting 7
    狗蛋带仨妞【Alpha】Scrum meeting 6
    狗蛋带仨妞【Alpha】Scrum meeting 5
    狗蛋带仨妞 【Alpha】Scrum meeting 1-4
    Rosetta中准备配体的参数文件
    pymol安装
    chemshell的creation之后
    关于KIE的一点认识
  • 原文地址:https://www.cnblogs.com/stragon/p/2708405.html
Copyright © 2011-2022 走看看