次のように、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);
}
}
次の 2 行でエラーが発生します。
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
これを実装する方法を見つけようとしていましたが、エラーに関連するものは見つかりませんでした。