Update Claims values in ASP.NET One Core

后端 未结 2 1092
甜味超标
甜味超标 2021-02-07 15:22

I have a Web Application in MVC 6 (Asp.Net One Core), and I\'m using Claims based authentication. In the Login method I set the Claims:

var claims = new Claim[]
         


        
相关标签:
2条回答
  • 2021-02-07 15:41

    I have to SignOutAsync and SignInAsync again in order to update the cookie?

    Answer is yes.

    Easiest way is you can manually sign-out and sign-in (create claims again) inside the same action method where you are updating the email.

    The best solution is to save this into a classic session?

    I suggest not to do that. Using session state explicitly is a bad practice in ASP.Net MVC.

    0 讨论(0)
  • 2021-02-07 15:52

    Another option, instead of SignOutAsync and SignInAsync, is to use RefreshSignInAsync.

    Example:

    var user = await _userManager.FindByIdAsync(yourId);
    await _signInManager.RefreshSignInAsync(user);
    

    View the RefreshSignInAsync code in the SignInManager (netcore 3.1.8): https://github.com/dotnet/aspnetcore/blob/c75b3f7a2fb9fe21fd96c93c070fdfa88a2fbe97/src/Identity/Core/src/SignInManager.cs#L169

    0 讨论(0)
提交回复
热议问题