Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions aspnetcore/blazor/call-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,37 @@ You can address this by flowing prerendered state using the Persistent Component

:::moniker-end

:::moniker range=">= aspnetcore-9.0"

## Client-side request streaming

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).

To enable request streaming, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserRequestStreamingEnabled%2A> to `true` on the <xref:System.Net.Http.HttpRequestMessage>.

In the following file upload example:

* `content` is the file's <xref:System.Net.Http.HttpContent>.
* `/Filesave` is the web API endpoint.
* `Http` is the <xref:System.Net.Http.HttpClient>.

```csharp
var request = new HttpRequestMessage(HttpMethod.Post, "/Filesave");
request.SetBrowserRequestStreamingEnabled(true);
request.Content = content;

var response = await Http.SendAsync(request);
```

Streaming requests:

* Require HTTPS protocol and don't work on HTTP/1.x.
* Include a body but not a `Content-Length` header. [CORS](xref:security/cors) with a preflight request is required for cross-origin streaming requests.

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).

:::moniker-end

## Add the `HttpClient` service

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

```csharp
builder.Services.AddScoped(sp =>
new HttpClient
{
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
});
new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
```

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.
Expand All @@ -385,10 +413,7 @@ If you're calling an external web API (not in the same URL space as the client a

```csharp
builder.Services.AddScoped(sp =>
new HttpClient
{
BaseAddress = new Uri("https://localhost:5001")
});
new HttpClient { BaseAddress = new Uri("https://localhost:5001") });
```

## JSON helpers
Expand Down
315 changes: 285 additions & 30 deletions aspnetcore/blazor/file-uploads.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions aspnetcore/fundamentals/servers/kestrel/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,22 @@ The following example configures an endpoint for HTTP/1.1, HTTP/2, and HTTP/3 co

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

:::moniker-end

:::moniker range=">= aspnetcore-9.0"

## Customize Kestrel named pipe endpoints

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.

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.

:::code language="csharp" source="~/fundamentals/servers/kestrel/endpoints/samples/KestrelNamedEP/Program.cs" highlight="15-33" id="snippet_1":::

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

## See also

* <xref:fundamentals/servers/kestrel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
// <snippet_1>
using System.IO.Pipes;
using System.Security.AccessControl;
using System.Security.Principal;

var builder = WebApplication.CreateBuilder();

builder.WebHost.ConfigureKestrel(options =>
{
options.ListenNamedPipe("pipe1");
options.ListenNamedPipe("pipe2");
options.ListenNamedPipe("defaultPipe");
options.ListenNamedPipe("securedPipe");
});

builder.WebHost.UseNamedPipes(options =>
{
options.CreateNamedPipeServerStream = (context) =>
{
var pipeSecurity = CreatePipeSecurity(context.NamedPipeEndpoint.PipeName);
var pipeName = context.NamedPipeEndPoint.PipeName;

switch (pipeName)
{
case "defaultPipe":
return NamedPipeTransportOptions.CreateDefaultNamedPipeServerStream(context);
case "securedPipe":
var allowSecurity = new PipeSecurity();
allowSecurity.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.FullControl, AccessControlType.Allow));

return NamedPipeServerStreamAcl.Create(context.NamedPipeEndPoint.PipeName, PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte,
context.PipeOptions, inBufferSize: 0, outBufferSize: 0, pipeSecurity);
return NamedPipeServerStreamAcl.Create(pipeName, PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte,
context.PipeOptions, inBufferSize: 0, outBufferSize: 0, allowSecurity);
default:
throw new InvalidOperationException($"Unexpected pipe name: {pipeName}");
}
};
});

var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();
// </snippet_1>
9 changes: 9 additions & 0 deletions aspnetcore/release-notes/aspnetcore-9/includes/blazor.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,12 @@ Trigger JavaScript callbacks either before or after enhanced navigation with new
* `blazor.addEventListener("enhancednavigationend", {CALLBACK})`

For more information, see <xref:blazor/js-interop/ssr?view=aspnetcore-9.0>.

### Client-side request streaming

Interactive WebAssembly rendering in Blazor now supports client-side request streaming using the `request.SetBrowserReqeustStreamingEnabled(true)` option on `HttpRequestMessage`.

For more information, see the following resources:

* <xref:blazor/call-web-api?view=aspnetcore-9.0#client-side-request-streaming>
* <xref:blazor/file-uploads?view=aspnetcore-9.0#file-size-read-and-upload-limits>
Loading
Loading