gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:14:16 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com