我无法找到一种方法如何将应用程序从aspnet核心1.1迁移到2.0使用cookie身份验证。CookieAuthentication和AspNet核心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
并设置options.Cookie.Name = "test"
的Configure
方法内。 我的事件试图手动创建并将Name属性设置为“Cookies”。
如果我尝试使用Startup.cs AddCookie
方法中的lambda表达式更改cookie的名称,它将按预期工作。但是,如果我不这样做,CookieAuthenticationOptionsSetup
从不使用,并使用默认的cookie名称(.AspNetCore.Cookies)。
我缺少什么?
**调用'AddCookie'后,请尝试注册您自定义的'CookieAuthenticationOptions' **。 – poke
我刚刚尝试过。没有成功。 – Zygimantas