ASP.net MVC:身份并删除身份验证 cookie

ASP.net MVC: Identity and drop auth cookie

我从不使用身份。所以阅读有关它的文章 http://www.asp.net/identity/overview/getting-started/introduction-to-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);
}

只是不明白上面几行代码中的哪一行代码drop auth cookie?请告诉我。

当我们处理身份时,如何删除将在接下来的 1 或 2 个月内保留在用户电脑中的身份验证 cookie。告诉我如何设置 auth cookie 过期时间。请指导。谢谢

您可以在配置开机认证时设置Cookie的过期时间。

public partial class Startup {
    public void Configuration(IAppBuilder app) {
         ConfigureAuth(app);
    }

    public void ConfigureAuth(IAppBuilder app) {

        // This uses cookie to store information for the signed in user
        var authOptions = new CookieAuthenticationOptions {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString(Constants.Paths.LoginPath), //Replace
            LogoutPath = new PathString(Constants.Paths.LogoutPath), //Replace
            //This sets the expiration of the cookie
            ExpireTimeSpan = System.TimeSpan.FromDays(60),   
        };            
        app.UseCookieAuthentication(authOptions);                      
    }
}