asp.net core - what are the differences of these MapRazorPages() calls?

4.2k Views Asked by At

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:

  1. Do the 2 method calls above have the same effect?
  2. Am I correct to assume that the second way (i.e. app.MapRazorPages()) is possible due to the middleware pipeline configuration by WebApplicationBuilder? (see snippet from MS docs above).

Thank you in advance.

1

There are 1 best solutions below

1
Brando Zhang On BEST ANSWER

Short answer: Yes. They are using the same method.

Details you could see below explain:

endpoint.MapRazorPages():

enter image description here

app.MapRazorPages();:

});