Tag: applicationmanager

当前上下文中不存在名称“DefaultAuthenticationTypes”

我正在尝试在我的Web应用程序中实现基于角色的授权,如下所示: [HttpPost] [ActionName(“Login”)] public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { string userName = model.Username; string[] userRoles = (string[])Session[“UserRoles”]; ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName)); userRoles.ToList().ForEach((role) => identity.AddClaim(new Claim(ClaimTypes.Role, role))); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); AuthenticationManager.SignIn(identity); return RedirectToAction(“Success”); } else { return View(“Login”,model); } } 我在两行上出错了: 1.ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); 和: 2.AuthenticationManager.SignIn(identity); 错误1: the […]