question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/dotnet/aspnetcore/issues/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?

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mkArtakMSFTcommented, Jan 30, 2023

@davidfowl, @twsouthwick it’s not clear whether there is still any work you need from Blazor as part of this issue or not? If not, can you please close this? Thanks!

0reactions
twsouthwickcommented, Jan 30, 2023

@davidfowl agree it should be in .NET 8. I chatted with @javiercn and he is planning on doing that and I’m assuming will drive any API changes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing System.Web Adapters v1.2 with new APIs and ...
Today, we're releasing an update to the System.Web Adapters that simplify upgrading from ASP.NET to ASP.NET Core.
Read more >
How to map fallback in ASP .NET Core Web API so that ...
You can fix this by explicitly mapping Blazor fallback only for paths that don't start with /api and, then only mapping api paths...
Read more >
Data Binding in Blazor DataGrid Component
Configure datagrid component using Web API adaptor. Now, you can configure the datagrid using the 'SfDataManager' to interact with the created Web API...
Read more >
Blazor WebAssembly & Web API on .NET 6 – Full Course (C#)
Learn Blazor WebAssembly and Web API on . NET 6 by building a shopping cart application using C#. This course also provides a...
Read more >
Deep Dive into System.Web Adapters [18 of 18] Migrating from ...
In this video, Taylor Southwick dives deeper into the System. Web adapters and how they help in ASP.NET to ASP.NET Core upgrade scenarios...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found