I am trying to convert a .NET Core 3.1 project to .NET 7.
When I use this in my Program.cs
class:
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
It gives me this message:
Suggest using top level route registrations UseEndpoints
Then, I clicked on Show potential fixes
in Visual Studio and it suggests this:
app.UseEndpoints(endpoints =>
{
_ = endpoints.MapRazorPages();
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Which looks the same to me.
In .NET 7, what should I do if I need to use RazorPages()?
Thanks!
CodePudding user response:
AFAIK it should work as is but the warning suggests to register the routes at the top-level of a minimal API application, i.e.:
app.MapRazorPages();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
See ASP0014: Suggest using top level route registrations code analysis rule.