Skip to content

Commit 6b7447d

Browse files
committed
Emit antiforgery only when streaming
1 parent bf73e6e commit 6b7447d

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ private async Task RenderComponentCore(HttpContext context)
7676
return;
7777
}
7878

79-
context.Response.OnStarting(() =>
80-
{
81-
// Generate the antiforgery tokens before we start streaming the response, as it needs
82-
// to set the cookie header.
83-
antiforgery!.GetAndStoreTokens(context);
84-
return Task.CompletedTask;
85-
});
86-
8779
if (httpActivityContext != default)
8880
{
8981
_activityLinkStore.SetActivityContext(ComponentsActivityLinkStore.Http, httpActivityContext, null);
@@ -154,6 +146,8 @@ await _renderer.InitializeStandardComponentServicesAsync(
154146

155147
if (!quiesceTask.IsCompletedSuccessfully)
156148
{
149+
// We need to ensure that the antiforgery tokens are generated and stored in the response
150+
antiforgery!.GetAndStoreTokens(context);
157151
await _renderer.SendStreamingUpdatesAsync(context, quiesceTask, bufferWriter);
158152
}
159153
else

0 commit comments

Comments
 (0)