3
我試圖實現基於角色的授權在我的web應用程序像下面:「DefaultAuthenticationTypes」這個名字不會在目前情況下存在
[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 name 'DefaultAuthenticationTypes' does not exist in the current context
和錯誤2:
Authentication manager does not contains definition for SignIn
我試圖找到一個解決方案如何實現這一點,但我找不到相關的錯誤東西。