Let's have web application from Visual Studio template using netcoreapp3.1.
It uses asp net identity, e.g. page gets refreshed upon click on Login button.
What I'm trying to achieve is to have SignalR Core hub method like this
[HttpGet]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<bool> Login(string email, string password)
{
var result = await _signInManager.PasswordSignInAsync(email,
password, true, lockoutOnFailure: false).ConfigureAwait(false);
if (result.Succeeded)
{
return true;
}
....
....
}
unfortunately for my naive attempt I 'll get InvalidOperationException: Headers are read-only, response has already started.
With horribly long stack trace ending with
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Item(String key, StringValues value)
at Microsoft.AspNetCore.Http.ResponseCookies.Append(String key, String value, CookieOptions options)
at Microsoft.AspNetCore.CookiePolicy.ResponseCookiesWrapper.Append(String key, String value, CookieOptions options)
at Microsoft.AspNetCore.Authentication.Cookies.ChunkingCookieManager.AppendResponseCookie(HttpContext context, String key, String value, CookieOptions options)
at Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.<HandleSignInAsync>d__25.MoveNext()
I found that for similar use-cases it's common to interact with HttpContext but I can't find way how it could play role in this scenario as ApplicationSignInManager seemed relatively independant to that.
I realize it's quite possible I'm missing something from conceptual point of view so every idea about how to get closer to desired goal is welcome.
Seems to be described here github issue so I'll need to think about redesign probably.