How to change authentication cookies after changing UserName of current user with asp.net identity

前端 未结 1 1752
鱼传尺愫
鱼传尺愫 2020-12-08 03:11

Using asp.net identity version 1.0.0-rc1 with Entity Framework 6.0.0-rc1 (the ones that come with Visual Studio 2013 RC).

Trying to give users an opportunity to chan

相关标签:
1条回答
  • 2020-12-08 03:50

    How do you login/authenticate a user with Asp.Net MVC5 RTM bits using AspNet.Identity?

    private async Task SignInAsync(ApplicationUser user, bool isPersistent)
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
    }
    

    For the RC1, You can use the similar code.

    AuthenticationManager.SignOut();
    IdentityManager.Authentication.SignIn(AuthenticationManager, user.UserId, isPersistent:false);
    

    For persistent value, you need to access the authentication cookie and retrieve the status.

    Updated:

    Use appropriate AuthenticationType used in place of "Bearer". Also make sure while issuing the signin ticket, you are setting the AuthenticationProperties.IsPersistent.

    bool isPersistent=false;
    var authContext = await Authentication.AuthenticateAsync("Bearer");
    if (authContext != null)
    {
       var aProperties = authContext.Properties;
       isPersistent = aProperties.IsPersistent;
    }
    
    0 讨论(0)
提交回复
热议问题