页面请求步骤:

1.登录地址: http://localhost:4441/SysLogin/AdminLogin

2.登陆成功地址:http://localhost:4441/Frame/MainFrame 

3.点击页面退出,清除Session/Cookie跳转到登录页面

4.Url输入登录成功的地址界面自动验证授权进入:http://localhost:4441/SysLogin/AdminLogin?ReturnUrl=%2fFrame%2fMainFrame

代码实现步骤:

1.登录页面:SysLogin/AdminLogin,不继承BaseController

[HttpPost]
        [OperateLoggerFilter(IsRecordLog = false, ConName = "系统登录", ActName = "用户登录")]
        public ActionResult LoginAuthentica(string Account, string Pwd)
        {
            try
            {
                var Result = AdminServiceDb.GetEntityByWhere(it => it.Account == Account);
                if (Result == null)
                {
                    return Json(new { result = false, msg = "用户不存在" });
                }
                else
                {
                    Pwd = StringHelper.MD5(Pwd);
                    if (Result.PassWord != Pwd)
                    {
                        return Json(new { result = false, msg = "密码错误" });
                    }
                    DateTime overdueDate;
                    string value = Result.ID.ToString();
                    value = Encrypt.Encrypto(value);
                    overdueDate = DateTime.Now.AddMinutes(30);
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                                1,
                                Guid.NewGuid().ToString(),
                                DateTime.Now,
                                overdueDate,
                                false,
                                value
                                );
                    FormsAuthenticationTicket t = new FormsAuthenticationTicket(0, "", DateTime.Now, overdueDate, false, value);
                    string hashTicket = FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket);
                    Response.Cookies.Add(cookie);
                    string url = Url.Action("MainFrame", "Frame");
                    return Json(new { result = true, msg = url });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(this, ex);
                return Json(new { result = false, msg = "异常:登录失败" });
            }
        }
登录方法

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2021-08-21
  • 2021-11-01
  • 2021-05-22
  • 2021-07-07
猜你喜欢
  • 2021-05-25
  • 2022-12-23
  • 2021-12-07
  • 2021-05-03
  • 2022-03-05
相关资源
相似解决方案