首页 > 编程语言 >ASP0014: Suggest using top level route registrations

ASP0014: Suggest using top level route registrations

时间:2022-11-18 10:58:30浏览次数:52  
标签:ASP0014 level Suggest app Program Build var builder

  最近在把.net core3.1迁移到.net 7上面,使用了顶级语法,所以只剩一个Program文件,在配置路由注册的时候,他一直有波浪线提示,我刚开始没细看,以为是什么启用或者过期的警告,就没管它,还是生效的,但是我这代码洁癖的人越看越不舒服,找了半天,总算找到了答案

如下图,其实是只有使用了顶级语法的Program才会有这种提示

 

 把它从

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
         name: "home",
         pattern: "{controller=Home}/{action=Login}/{id?}");
});

app.Run();

改成这种最外层注册方式就可以了

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapControllerRoute
(
    name: "home",
    pattern: "{controller=Home}/{action=Login}/{id?}"
);

app.Run();

 

标签:ASP0014,level,Suggest,app,Program,Build,var,builder
From: https://www.cnblogs.com/corechen/p/16902475.html

相关文章