首页 新闻 会员 周边

咨询下.net core mvc默认路由失效

0
悬赏园豆:10 [已解决问题] 解决于 2021-02-24 14:30

为什么直接访问http://localhost:5006/会出现404页面,但是访问http://localhost:5006/home/index页面正常显示。
代码如下:

[Route("home")]
public class HomeController: Controller
{
    [Route("index")]
    [HttpGet]
    public IActionResult Index()
    {
        return View();
    }
}

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
        }
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=home}/{action=index}/{id?}");
        });
    }
灬丶的主页 灬丶 | 初学一级 | 园豆:2
提问于:2021-02-24 14:27
< >
分享
最佳答案
0

属性路由覆盖了默认路由

收获园豆:10
dudu | 高人七级 |园豆:30994 | 2021-02-24 14:29

谢谢大佬

灬丶 | 园豆:2 (初学一级) | 2021-02-24 14:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册