ASP.NET Core 8 с кодом состояния входа в Google невозможно установить, поскольку ответ уже начался. ⇐ C#
ASP.NET Core 8 с кодом состояния входа в Google невозможно установить, поскольку ответ уже начался.
I'm working on an ASP.NET Core 8 application using Identity for authentication, including Google sign-in. After successfully signing in with Google, the application redirects to /signin-google, but this results in an unhandled exception: (Access token and refresh token are well generated and works) Exception screen System.InvalidOperationException: StatusCode cannot be set because the response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)
Here's my AuthController:
[ApiController] [Route("[controller]")] public class AuthController : ControllerBase { private readonly ILogger _logger; private readonly SignInManager _signInManager; public AuthController( ILogger logger, SignInManager signInManager) { _logger = logger; _signInManager = signInManager; } [HttpGet("google")] public IActionResult Login() { var properties = _signInManager.ConfigureExternalAuthenticationProperties( GoogleDefaults.AuthenticationScheme, null); return Challenge(properties, GoogleDefaults.AuthenticationScheme); } } And my Program.cs:
public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Services.AddAuthentication(IdentityConstants.BearerScheme) .AddGoogle(googleOptions => { googleOptions.ClientId = "client"; googleOptions.ClientSecret = "secret"; }) .AddBearerToken(IdentityConstants.BearerScheme); builder.Services.AddAuthorizationBuilder(); builder.Services.AddDbContext(x => x.UseInMemoryDatabase("AuthNet8")); builder.Services.AddIdentityCore() .AddEntityFrameworkStores() .AddApiEndpoints(); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); } } What could be causing this InvalidOperationException and how can I fix it? Any ideas ?
I've tried modifying the middleware order, but the problem persists.
Источник: https://stackoverflow.com/questions/780 ... e-response
I'm working on an ASP.NET Core 8 application using Identity for authentication, including Google sign-in. After successfully signing in with Google, the application redirects to /signin-google, but this results in an unhandled exception: (Access token and refresh token are well generated and works) Exception screen System.InvalidOperationException: StatusCode cannot be set because the response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)
Here's my AuthController:
[ApiController] [Route("[controller]")] public class AuthController : ControllerBase { private readonly ILogger _logger; private readonly SignInManager _signInManager; public AuthController( ILogger logger, SignInManager signInManager) { _logger = logger; _signInManager = signInManager; } [HttpGet("google")] public IActionResult Login() { var properties = _signInManager.ConfigureExternalAuthenticationProperties( GoogleDefaults.AuthenticationScheme, null); return Challenge(properties, GoogleDefaults.AuthenticationScheme); } } And my Program.cs:
public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Services.AddAuthentication(IdentityConstants.BearerScheme) .AddGoogle(googleOptions => { googleOptions.ClientId = "client"; googleOptions.ClientSecret = "secret"; }) .AddBearerToken(IdentityConstants.BearerScheme); builder.Services.AddAuthorizationBuilder(); builder.Services.AddDbContext(x => x.UseInMemoryDatabase("AuthNet8")); builder.Services.AddIdentityCore() .AddEntityFrameworkStores() .AddApiEndpoints(); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); } } What could be causing this InvalidOperationException and how can I fix it? Any ideas ?
I've tried modifying the middleware order, but the problem persists.
Источник: https://stackoverflow.com/questions/780 ... e-response
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение