Skip to content

Streaming rendering with Azure hosting 8.0 #30820

@guardrex

Description

@guardrex

Description

From @iphdav on #30504 ...

I wanted to add a few comments for you to consider when writing up the documents.

I was putting together a blazor streaming rendering demo and decided to have it obtain data to display on the page from a separate minimal API that streamed back data using IAsyncEnumerable.

It worked perfectly locally, but when deployed to an Azure Web App, even my minimal API appeared to not be streaming. I was not sure the exact backend architecture of Azure (YARP respone caching, etc), but noticed if I added this after each items was yield returned (within the IAsyncEnumerable):

await context.Response.Body.FlushAsync();

It did correctly stream when deployed to Azure. Flushing the response buffer was not needed when running locally on Kestrel.

It would be interesting if this customer did the same thing in his streaming blazor project to see if it streamed correctly for his particular hosting provider when flushing the buffer after each async update to his page (when streaming rendering the response).

But if you are writing up the documents, maybe just include some general comments and suggestions including configuring the web server, but also flushing the response as shown above.

I think in RC2, the HttpContext will be registered globally as a CascadingParameter. At that point, I would be interesting to document this as a potential solution to caching (compared to the default template).

First the component would need to inject the HttpContext using the new technique (which will not work until RC2):

[CascadingParameter] HttpContext Ctx;

In the demo project template, where there is a delay awaited, to add flushing the buffer like this:

await Task.Delay(2000);
await Ctx?.Response.Body.FlushAsync();

It would be interesting to check if this worked, and include this in the docs for Azure (etc) if it does work.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/rendering.md

Document ID

27742f9a-95e5-a2d0-aa54-0ef24cad3d2a

Article author

guardrex

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions