随机错误 在一段时间后,mvc应用程序无法找到指定的文件
随机错误 在一段时间后,mvc应用程序无法找到指定的文件
我正在使用基于声明的身份验证的MVC应用程序,在本地和Web服务器上都可以正常工作。
下面是登录操作的代码:
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } var repository = new AccountRepository(); var user = repository.Get().Where(x => x.Username == model.Username).FirstOrDefault(); if (user != null) { var password = EncryptionKeys.Encrypt(model.Password); if (user.Password.Equals(password)) { var userRole = (EnumUserRole)new RoleRepository().Get(user.RoleId).Code; var claims = new List(); claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Username)); claims.Add(new Claim(ClaimTypes.Name, user.FirstName)); claims.Add(new Claim(ClaimTypes.Email, user.Email)); claims.Add(new Claim(ClaimTypes.Role, userRole.ToString("g"))); claims.Add(new Claim(ClaimTypes.Sid, user.Id.ToString())); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id); return RedirectToPortal(userRole, user); } } }
问题是随机地经过一段时间后会出现错误。错误是系统找不到指定的文件,但堆栈跟踪表明网络连接未建立,请参见图像1。
[图像1](https://i.stack.imgur.com/OLJxA.png)
但是在Chrome中检查时,.AspNet.ApplicationCookie存在,如果我编辑并删除cookie,则应用程序可以正常工作。
[图像2](https://i.stack.imgur.com/T3Haq.png)