Identity Frameworkを使用してASP.Netアプリケーションを作成しました。ユーザ認証に成功した後、System.Web.HttpContext.Current.User.Identity
はnull
で、System.Web.HttpContext.Current.User.Identity.IsAuthenticated
がfalse
ログイン認証後、ユーザーはNullです
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
switch (result)
{
case SignInStatus.Success:
ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
UserManager.AddClaim(User.Identity.GetUserId(),new Claim(ClaimTypes.Role,"Admin"));
である私は、認証後に認証されたユーザに対して、いくつかの役割を追加する必要があります。
最初のリダイレクト後にユーザーIDを取得できます – anand