Add razor service

Add razor service

let us modify the program code as shown:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();

var app = builder.Build();

//app.MapGet("/", () => "Hello ASP World!");
app.MapRazorPages();

app.Run();

Restart

Hot reload may not always work especially when we have non visual changes like the one we did above, so let us restart the app and then we should see the following output on the browser

If we omit app.MapRazorPages()then razor Pages will not be served to clients, even if they are present in your project. Instead, clients will receive a "404 Not Found" error if they attempt to access any URL routes that correspond to your Razor Pages.

Routing

Currently the application is using convention based routing over any configuration. We will later see how we can further configure the route as and when required.

Last updated