Method 1
In ASP.NET Core 3.x, we add endpoints for Razor Pages with
app.UseEndpoints(endpoint =>
{
endpoint.MapRazorPages();
});
Method 2
In the ASP.NET Core 6 Web App template (minimal hosting model), this has been changed to:
app.MapRazorPages();
From MS docs page:
Apps typically don't need to call UseRouting or UseEndpoints. WebApplicationBuilder configures a middleware pipeline that wraps middleware added in Program.cs with UseRouting and UseEndpoints. For more information, see Routing in ASP.NET Core.
My questions are:
- Do the 2 method calls above have the same effect?
- Am I correct to assume that the second way (i.e.
app.MapRazorPages()) is possible due to the middleware pipeline configuration byWebApplicationBuilder? (see snippet from MS docs above).
Thank you in advance.
Short answer: Yes. They are using the same method.
Details you could see below explain:
endpoint.MapRazorPages():
app.MapRazorPages();: