2
votes

I've previously asked this question for Blazor around the time when the 3.0 preview was out. Is there a way to serve a Blazor app from a specific controller action in a MVC app?

Since then Blazor 3.2 has arrived, I did some research on how to accomplish this, I tried following the examples on this github issue but didn't really manage to get it working.

https://github.com/dotnet/aspnetcore/issues/20642

Thoughts?

2

2 Answers

2
votes

Try this:

public IActionResult MyAction([FromServices] IWebHostEnvironment webHost)
{
    var file = webHost.WebRootFileProvider.GetFileInfo("index.html");
    return PhysicalFile(file.PhysicalPath, "text/html");
}

And change fallback in Startup.cs to:

app.UseEndpoints(endpoints =>
{
    ...
    endpoints.MapFallbackToController("MyAction","controller")
});
0
votes

A mix of Kazbek's answer and this post helped me to integrate blazor wasm to the existing MVC site. Now I have wasm served by a controller action protected by [Authorize].