/// <summary> /// Ajax调用的接口 /// </summary> /// <param name="info"></param> /// <returns></returns> public IActionResult OnPostLogin(string userID, string password) { log.InfoFormat("UserID:{0}", userID); log.InfoFormat("Password:{0}", password); AjaxMsg msg = new AjaxMsg(); string userName; bool br = _LoginService.LoginUser(userID, password, out userName); msg.Success = br; msg.ReturnMessage = ""; if (br == false) { m_LoginResult = "用户号或者密码错误,请重试"; msg.ReturnMessage = LoginResult; } else { //登陆成功,将登录信息保存到cookie var claims = new[] { new Claim("UserName", userName) }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal user = new ClaimsPrincipal(claimsIdentity); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user); } return(new JsonResult(msg)); }