Asp.net MVC Web サイトに基本的な認証システムがあります
[HttpPost]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
WebSecurity.Login(model.UserName, model.Password, persistCookie: false)
return RedirectToAction("Index", "Home");
}
また、UserInfoViewModelユーザー固有の情報を保持するクラスもあり、それをさまざまなページで使用しています。
UserInfoViewModel必要なたびに作成するのを避けるために、Session on Login メソッドに保存したいと思います。
public ActionResult Login(LoginViewModel model, string returnUrl)
{
WebSecurity.Login(model.UserName, model.Password, persistCookie: false)
var userInfoViewModel = new UserInfoViewModel();
Session["userInfo"] = userInfoViewModel;
return RedirectToLocal(returnUrl);
}
UserInfoViewModelのような内部に依存する機密情報があることを考えると、IsSuperuserそのオブジェクトをセッションに保持しても安全ですか? ユーザー ログイン セッションが期限切れになると期限切れになりますか?
解決
System.Security.Principal.IIdentityまさにそのために作られています。必要なカスタムユーザー情報を AUTH Cookie 内に保存するため、毎回再計算する必要はありません。
カスタム プリンシパル オブジェクトを使用するビデオ チュートリアル
回答ありがとうございます。