Tôi đang cố gắng làm theo các hướng dẫn here để thêm Xác thực Cookie vào trang web của tôi.InvalidOperationException: Không có IAuthenticationSignInHandler được cấu hình để xử lý đăng nhập cho lược đồ: MyCookieAuthenticationScheme
Cho đến nay tôi đã thêm như sau:
Invoke the UseAuthentication method in the Configure method of the Startup.cs file:
app.UseAuthentication();
Invoke the AddAuthentication and AddCookie methods in the ConfigureServices method of the Startup.cs file:
services.AddAuthentication("MyCookieAuthenticationScheme")
.AddCookie(options => {
options.AccessDeniedPath = "/Account/Forbidden/";
options.LoginPath = "/Account/Unauthorized/";
});
Trong mã đăng nhập của tôi sau đó tôi có
await HttpContext.SignInAsync("MyCookieAuthenticationScheme", principal);
principle
là một ClaimsPrincipal
.
Khi tôi đăng nhập vào trang web của tôi và gọi dòng ở trên tôi nhận được lỗi:
InvalidOperationException: No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme
Tôi đã bỏ lỡ gì ra?
Cảm ơn bạn! Tôi đã cố gắng tìm ra điều này hầu hết trong ngày. Rất nhiều ví dụ trên mạng nhưng họ bỏ qua trình xử lý xác thực. – Tom