在启动过程中,我配置了Identity auth cookie:
services.ConfigureApplicationCookie(x =>
{
x.Cookie.Name = "foo"; // default is ".AspNetCore.Identity.Application"
// other config...
});
在运行时我需要cookie的信息,所以在某个控制器中我注入IOptions<CookieAuthenticationOptions>
,然后try 获取cookie名称:
var cookieName = cookieAuthenticationOptions.Value.Cookie;
这是".AspNetCore."
而不是"foo"
.该对象的其他属性也是错误的,它们似乎都是默认值.
为什么会发生这种情况,以及如何获得该选项对象的有效实例?