asp.net-mvc - ASP.net MVC : Identity and drop auth

我从不使用身份。所以阅读有关它的文章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);                      
    }
}

关于asp.net-mvc - ASP.net MVC : Identity and drop auth cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35484699/

相关文章:

sql - Knex 原始查询不工作 postgresql

ruby - 如何使用 Chef Recipe 删除文件中的一行?

turing-machines - PCP 可以识别吗?

html-table - 在单个表格行 中混合表格标题 和表格数据 单

python - 如何在 python 中将对象作为命令行参数传递?

python - 使用 gensim 库进行内存高效 LDA 训练

oracle - 安装 Oracle ODAC 12c 第 4 版 (12.1.0.2.4) 时出现

visual-studio - 如何在 Google Chrome 扩展程序中创建侧边栏?

makefile - 使用 GNU Make 处理带空格的文件名

amazon-web-services - 更新和部署 Elastic Beanstalk 应用程序