Skip to content

Add API to System.Web adapters to enable explicitly mapping Blazor pages #46170

@twsouthwick

Description

@twsouthwick

Background and Motivation

We created a set of adapters and guidance (https://github.com/dotnet/systemweb-adapters) to simplify the migration process from ASP.NET to ASP.NET Core. As part of this, we have recommended people set up a ASP.NET Core application that will attempt to serve requests and fallback to the original ASP.NET framework application via YARP. This works well for many things, but it fails when trying to use Blazor. This is because currently both Blazor and YARP are fallback endpoints and this conflicts with each other.

See #42003 for an existing issue on dotnet/aspnetcore that is tracking the need for this.

Proposed API

For the dotnet/systemweb-adapters, I have implemented an extension method that will accomplish this need. However, as this is a feature planned for .NET 8, I want to ensure we have identified a few things:

  1. The API in the web adapters should be useable for .NET 6 and .NET 7, but provide a way to migrate to the official .NET 8 API
  2. We don't want to conflict with the API design for .NET 8

Here is the public API for this that we are currently exposing on the Microsoft.AspNetCore.SystemWebAdapters package:

namespace Microsoft.AspNetCore.Builder;

public static class BlazorEndpointRouteBuilderExtensions
{
+    public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page);
+    public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page, params Assembly[] assemblies)
}

Usage Examples

An example usage would be:

app.MapBlazorHub();

// This is the default way to set up Blazor pages
//app.MapFallbackToPage("/_Host");

// Proposed API
app.MapBlazorPages("/_Host");

app.MapReverseProxy();

Risks

  • How do we prevent this API from conflicting with an API for .NET 8 that will accomplish a similar thing but still available for down level?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions