How to remember the login in MVC5 when an external provider is used

后端 未结 3 1440
走了就别回头了
走了就别回头了 2021-01-05 17:42

In our MVC5-application with OWIN, we use additional to the local accounts also external logins (google). When the user logs in with its local account, he can activate the o

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-05 18:29

    To follow up on what Hao Kung suggested.

    You will find the line of code in question in the accountController.cs file. The default function is:

    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);
        }
    

    To enable the remember me functionality with all external providers, change the line:

    AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent}, identity);
    

    by changing the isPersistent varible to the constant true:

    AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true}, identity);
    

提交回复
热议问题