我正在学习服务器端 blazor 并尝试学习身份验证。每当我使用 SignInManager.SignInAsync(.......) 时,它都会引发以下异常:
System.InvalidOperationException:无法修改响应标头,因为响应已开始。 在 Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.ThrowIfReadOnly() 在 Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.set_Item(String key, StringValues value) 在 Microsoft.AspNetCore.Http.ResponseCookies.Append(String key, String value, CookieOptions 选项) 位于 Microsoft.AspNetCore.Authentication.Cookies.ChunkingCookieManager.AppendResponseCookie(HttpContext context、String key、String value、CookieOptions options) 位于 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleSignInAsync(ClaimsPrincipal 用户、AuthenticationProperties 属性) 位于 Microsoft。 AspNetCore.Authentication.AuthenticationService.SignInAsync(HttpContext 上下文、字符串方案、ClaimsPrincipal 主体、AuthenticationProperties 属性) 位于 Microsoft.AspNetCore.Identity.SignInManager
1.SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable1 extraClaims),位于 C:\my_work\Blazor_learning\GroupMembersInfo 中的 GroupMembersInfo.Pages.RegisterUser.Register() \Pages\RegisterUser.razor:第 52 行位于 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(任务任务)位于 Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
位于 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(任务任务) )在 Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(任务 taskToHandle)
我认为异常是从我突出显示的方法中抛出的。那么我该如何缓解这个问题。这是我的代码
启动程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using …Run Code Online (Sandbox Code Playgroud)