【发布时间】:2018-01-27 22:52:25
【问题描述】:
我找不到如何将应用程序从 aspnet core 1.1 迁移到使用 cookie 身份验证的 2.0 的方法。
我已经知道的最有用的资源是:
- https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#cookie-based-authentication
- https://github.com/aspnet/announcements/issues/262
- https://github.com/aspnet/Home/issues/2128(我自己的问题)
不幸的是,我仍然卡住了。这是我的做法:
在 Startup.cs ConfigureServices(IServiceCollection services)我有:
services.AddSingleton<IConfigureNamedOptions<CookieAuthenticationOptions>, CookieAuthenticationOptionsSetup>();
及以后:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
CookieAuthenticationOptionsSetup 类实现IConfigureNamedOptions 并在Configure 方法中设置options.Cookie.Name = "test"。
我尝试手动创建 Name 属性并将其设置为“Cookies”。
如果我尝试在 Startup.cs AddCookie 方法中使用 lambda 表达式更改 cookie 的名称,它会按预期工作。但如果我不这样做,则永远不会使用 CookieAuthenticationOptionsSetup并使用默认的 cookie 名称 (.AspNetCore.Cookies)。
我错过了什么?
【问题讨论】:
-
请尝试注册您的自定义
CookieAuthenticationOptions之后调用AddCookie。 -
我刚刚尝试过。没有成功。
标签: c# asp.net-mvc cookies asp.net-core migration