2
votes

I have a Blazor WebAssembly Hosted solution (Client and Server) setup with IdentityServer for Authentication. I am looking to do 2 things...

  1. I would like to set up MVC on the Server since I am more comfortable with MVC. The idea for Server Side pages would be for things like Profile Management and accessing Content that I do not want to on the Client.

The Server Startup.cs currently has

public void ConfigureServices(IServiceCollection services)
        {
            ....Condensed

            services.AddControllersWithViews();
            services.AddRazorPages();
        }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext dataContext)
        {
           .....Condensed

           app.UseRouting();

            app.UseIdentityServer();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }

  1. With MVC setup on the backend, how can I navigate to these pages from the Client?
1
Usually when I want to add a framework to an application, I use VS or the command line to create a new empty application of the type I want. Then I examine the configuration it automatically generated, and piece by piece copy the relevant configuration into my existing application.mason

1 Answers

2
votes

When you create your WebAssembly solution, be sure to check the box "ASP.Net Core Hosted".

This will create three projects: Client, Shared, and Server.

In the server project you will find a Controllers folder. Go ahead and add a controller, such as DummyController.cs

namespace BlazorWASM4.Server.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class DummyController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Then right-click on your controller method Index and click 'Add View'. Then implement the view (Index.cshtml) like this for example:

<h1>Dummy Page</h1>

Run the project and navigate to localhost:port/Dummy

You should see your new page get displayed.