How to serve blazor app from a controller action in ASP.NET Core

Viewed 343
2 Answers

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")
});

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

Related