【问题标题】:ASP.net MVC: Identity and drop auth cookieASP.net MVC:身份和删除身份验证 cookie
【发布时间】:2016-05-30 19:26:13
【问题描述】:

我从不使用身份。所以阅读一篇关于它的文章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?请告诉我。

当我们处理身份时,如何删除将在用户 PC 中持续 1 或 2 个月的身份验证 cookie。告诉我如何设置 auth cookie 过期时间。请指导。谢谢

【问题讨论】:

  • 你所说的“下降”是什么意思?你的意思是创建 cookie 吗?

标签: asp.net-mvc cookies asp.net-identity


【解决方案1】:

您可以在配置启动认证时设置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);                      
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2011-08-19
    • 2011-02-28
    • 1970-01-01
    • 2012-02-08
    相关资源
    最近更新 更多