Код: Выделить всё
public async Task OnPostAsync()
{
if (!ModelState.IsValid) return Page();
//verfiy the credential
if(Credential.UserName == "admin" && Credential.Password == "password")
{
//Creating the security context
var claims = new List {
new Claim(ClaimTypes.Name, "admin"),
new Claim(ClaimTypes.Email, "admin@mywebsite.com")
};
var identity = new ClaimsIdentity(claims, "MyCookieAuth");
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync("MyCookieAuth", claimsPrincipal);
return RedirectToPage("/Index");
}
return Page();
}
fail:
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
Необработанный при обработке запроса произошло исключение.
InvalidOperationException: обработчики аутентификации при входе не зарегистрированы. Вы забыли вызвать AddAuthentication().AddCookie("MyCookieAuth",...)?
.
.
.
в Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke( Контекст HttpContext)
Подробнее здесь: https://stackoverflow.com/questions/722 ... l-throwing
Мобильная версия