我正在尝试按照此处的说明将 Cookie 身份验证添加到我的网站。
到目前为止,我已经添加了以下内容:
在 Startup.cs 文件的 Configure 方法中调用 UseAuthentication 方法:
app.UseAuthentication();
在 Startup.cs 文件的 ConfigureServices 方法中调用 AddAuthentication 和 AddCookie 方法:
services.AddAuthentication("MyCookieAuthenticationScheme")
.AddCookie(options => {
options.AccessDeniedPath = "/Account/Forbidden/";
options.LoginPath = "/Account/Unauthorized/";
});
然后在我的登录代码中
await HttpContext.SignInAsync("MyCookieAuthenticationScheme", principal);
principle
是一个ClaimsPrincipal
。
当我登录到我的网站并调用上面的行时,我收到错误:
InvalidOperationException:未配置 IAuthenticationSignInHandler 来处理方案的登录:MyCookieAuthenticationScheme
我错过了什么?