app.UseCookieAuthentication 似乎不适用于 cookiename 或 expiretimespan
app.UseCookieAuthentication does not seem to be working for cookiename or expiretimespan
在 asp.net 5 + (asp.net identity 3.0) 中,我正在尝试重命名 cookie 并查看是否可以将注销值设置为默认值。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIdentity();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "MyCookie",
ExpireTimeSpan = TimeSpan.FromMinutes(1.0),
});
}
Cookie 名称未重命名为 MyCookie,ExpireTimeSpan = TimeSpan.FromMinutes(1.0) 未“在 1 分钟后注销我”或设置 . 我确实被重定向到
尝试在您的 CookieAuthenticationOptions
:
中添加这些行
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "MyCookie",
ExpireTimeSpan = TimeSpan.FromMinutes(1.0),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
TimeSpan.FromMinutes(1.0),
(manager, user) => user.GenerateUserIdentityAsync(manager, user))
}
});
正如我在 Identity 2.0 中看到的那样,配置与 3.0 中的相同,这些是一个工作示例。您需要向 Identity
提供商提供设置
原来你要用
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<ApplicationUser, ApplicationRole>(
options => {
options.Cookies.ApplicationCookieAuthenticationScheme = "MyCookie";
options.Cookies.ApplicationCookie.AuthenticationScheme = IdentityCookieOptions.ApplicationCookieAuthenticationType = "MyCookie";
options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromSeconds(30.0);
options.Cookies.ApplicationCookie.CookieName = "MyCookie";
})
}
我正在使用 IApplicationBuilder 应用程序
app.UseIdentity().UseCookieAuthentication(
new CookieAuthenticationOptions
{
...等等
所以基本上使用 IServiceCollection AddIdentity 解决了我的问题。
在 asp.net 5 + (asp.net identity 3.0) 中,我正在尝试重命名 cookie 并查看是否可以将注销值设置为默认值。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIdentity();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "MyCookie",
ExpireTimeSpan = TimeSpan.FromMinutes(1.0),
});
}
Cookie 名称未重命名为 MyCookie,ExpireTimeSpan = TimeSpan.FromMinutes(1.0) 未“在 1 分钟后注销我”或设置 . 我确实被重定向到
尝试在您的 CookieAuthenticationOptions
:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "MyCookie",
ExpireTimeSpan = TimeSpan.FromMinutes(1.0),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
TimeSpan.FromMinutes(1.0),
(manager, user) => user.GenerateUserIdentityAsync(manager, user))
}
});
正如我在 Identity 2.0 中看到的那样,配置与 3.0 中的相同,这些是一个工作示例。您需要向 Identity
提供商提供设置
原来你要用
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<ApplicationUser, ApplicationRole>(
options => {
options.Cookies.ApplicationCookieAuthenticationScheme = "MyCookie";
options.Cookies.ApplicationCookie.AuthenticationScheme = IdentityCookieOptions.ApplicationCookieAuthenticationType = "MyCookie";
options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromSeconds(30.0);
options.Cookies.ApplicationCookie.CookieName = "MyCookie";
})
}
我正在使用 IApplicationBuilder 应用程序
app.UseIdentity().UseCookieAuthentication(
new CookieAuthenticationOptions
{
...等等
所以基本上使用 IServiceCollection AddIdentity 解决了我的问题。