Skip to content

Commit 6f5fd10

Browse files
Merge pull request #34876 from dotnet/main
Merge to Live
2 parents 41b6b7c + a135bea commit 6f5fd10

File tree

7 files changed

+404
-111
lines changed

7 files changed

+404
-111
lines changed

aspnetcore/blazor/call-web-api.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,37 @@ You can address this by flowing prerendered state using the Persistent Component
353353

354354
:::moniker-end
355355

356+
:::moniker range=">= aspnetcore-9.0"
357+
358+
## Client-side request streaming
359+
360+
For Chromium-based browsers (for example, Google Chrome and Microsoft Edge) using the HTTP/2 protocol, and HTTPS, client-side Blazor uses [Streams API](https://developer.mozilla.org/docs/Web/API/Streams_API) to permit [request streaming](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests).
361+
362+
To enable request streaming, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserRequestStreamingEnabled%2A> to `true` on the <xref:System.Net.Http.HttpRequestMessage>.
363+
364+
In the following file upload example:
365+
366+
* `content` is the file's <xref:System.Net.Http.HttpContent>.
367+
* `/Filesave` is the web API endpoint.
368+
* `Http` is the <xref:System.Net.Http.HttpClient>.
369+
370+
```csharp
371+
var request = new HttpRequestMessage(HttpMethod.Post, "/Filesave");
372+
request.SetBrowserRequestStreamingEnabled(true);
373+
request.Content = content;
374+
375+
var response = await Http.SendAsync(request);
376+
```
377+
378+
Streaming requests:
379+
380+
* Require HTTPS protocol and don't work on HTTP/1.x.
381+
* Include a body but not a `Content-Length` header. [CORS](xref:security/cors) with a preflight request is required for cross-origin streaming requests.
382+
383+
For more information on file uploads with an <xref:Microsoft.AspNetCore.Components.Forms.InputFile> component, see <xref:blazor/file-uploads#file-size-read-and-upload-limits> and the example at [Upload files to a server with client-side rendering (CSR)](xref:blazor/file-uploads#upload-files-to-a-server-with-client-side-rendering-csr).
384+
385+
:::moniker-end
386+
356387
## Add the `HttpClient` service
357388

358389
*The guidance in this section applies to client-side scenarios.*
@@ -368,10 +399,7 @@ In the `Program` file, add an <xref:System.Net.Http.HttpClient> service if it is
368399

369400
```csharp
370401
builder.Services.AddScoped(sp =>
371-
new HttpClient
372-
{
373-
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
374-
});
402+
new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
375403
```
376404

377405
The preceding example sets the base address with `builder.HostEnvironment.BaseAddress` (<xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment.BaseAddress%2A?displayProperty=nameWithType>), which gets the base address for the app and is typically derived from the `<base>` tag's `href` value in the host page.
@@ -385,10 +413,7 @@ If you're calling an external web API (not in the same URL space as the client a
385413

386414
```csharp
387415
builder.Services.AddScoped(sp =>
388-
new HttpClient
389-
{
390-
BaseAddress = new Uri("https://localhost:5001")
391-
});
416+
new HttpClient { BaseAddress = new Uri("https://localhost:5001") });
392417
```
393418

394419
## JSON helpers

aspnetcore/blazor/file-uploads.md

Lines changed: 285 additions & 30 deletions
Large diffs are not rendered by default.

aspnetcore/fundamentals/servers/kestrel/endpoints.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,22 @@ The following example configures an endpoint for HTTP/1.1, HTTP/2, and HTTP/3 co
581581

582582
:::code language="csharp" source="~/fundamentals/servers/kestrel/samples/6.x/KestrelSample/Snippets/Program.cs" id="snippet_ConfigureKestrelProtocols":::
583583

584+
:::moniker-end
585+
586+
:::moniker range=">= aspnetcore-9.0"
587+
588+
## Customize Kestrel named pipe endpoints
589+
590+
Kestrel's named pipe support includes advanced customization options. The [CreateNamedPipeServerStream](/dotnet/api/microsoft.aspnetcore.server.kestrel.transport.namedpipes.namedpipetransportoptions.createnamedpipeserverstream) property on the named pipe options allows pipes to be customized per-endpoint.
591+
592+
This is useful, for example, in a Kestrel app that requires two pipe endpoints with different [access security](/windows/win32/ipc/named-pipe-security-and-access-rights). The `CreateNamedPipeServerStream` option can be used to create pipes with custom security settings, depending on the pipe name.
593+
594+
:::code language="csharp" source="~/fundamentals/servers/kestrel/endpoints/samples/KestrelNamedEP/Program.cs" highlight="15-33" id="snippet_1":::
595+
596+
:::moniker-end
597+
598+
:::moniker range=">= aspnetcore-8.0"
599+
584600
## See also
585601

586602
* <xref:fundamentals/servers/kestrel>
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
1+
// <snippet_1>
12
using System.IO.Pipes;
3+
using System.Security.AccessControl;
4+
using System.Security.Principal;
25

36
var builder = WebApplication.CreateBuilder();
47

58
builder.WebHost.ConfigureKestrel(options =>
69
{
7-
options.ListenNamedPipe("pipe1");
8-
options.ListenNamedPipe("pipe2");
10+
options.ListenNamedPipe("defaultPipe");
11+
options.ListenNamedPipe("securedPipe");
912
});
1013

1114
builder.WebHost.UseNamedPipes(options =>
1215
{
1316
options.CreateNamedPipeServerStream = (context) =>
1417
{
15-
var pipeSecurity = CreatePipeSecurity(context.NamedPipeEndpoint.PipeName);
18+
var pipeName = context.NamedPipeEndPoint.PipeName;
19+
20+
switch (pipeName)
21+
{
22+
case "defaultPipe":
23+
return NamedPipeTransportOptions.CreateDefaultNamedPipeServerStream(context);
24+
case "securedPipe":
25+
var allowSecurity = new PipeSecurity();
26+
allowSecurity.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.FullControl, AccessControlType.Allow));
1627

17-
return NamedPipeServerStreamAcl.Create(context.NamedPipeEndPoint.PipeName, PipeDirection.InOut,
18-
NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte,
19-
context.PipeOptions, inBufferSize: 0, outBufferSize: 0, pipeSecurity);
28+
return NamedPipeServerStreamAcl.Create(pipeName, PipeDirection.InOut,
29+
NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte,
30+
context.PipeOptions, inBufferSize: 0, outBufferSize: 0, allowSecurity);
31+
default:
32+
throw new InvalidOperationException($"Unexpected pipe name: {pipeName}");
33+
}
2034
};
2135
});
36+
37+
var app = builder.Build();
38+
39+
app.MapGet("/", () => "Hello World!");
40+
41+
app.Run();
42+
// </snippet_1>

aspnetcore/release-notes/aspnetcore-9/includes/blazor.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,12 @@ Trigger JavaScript callbacks either before or after enhanced navigation with new
227227
* `blazor.addEventListener("enhancednavigationend", {CALLBACK})`
228228

229229
For more information, see <xref:blazor/js-interop/ssr?view=aspnetcore-9.0>.
230+
231+
### Client-side request streaming
232+
233+
Interactive WebAssembly rendering in Blazor now supports client-side request streaming using the `request.SetBrowserReqeustStreamingEnabled(true)` option on `HttpRequestMessage`.
234+
235+
For more information, see the following resources:
236+
237+
* <xref:blazor/call-web-api?view=aspnetcore-9.0#client-side-request-streaming>
238+
* <xref:blazor/file-uploads?view=aspnetcore-9.0#file-size-read-and-upload-limits>

0 commit comments

Comments
 (0)