为什么直接访问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?}");
});
}
属性路由覆盖了默认路由
谢谢大佬