在ASP.NET 6中,不再使用UseMvc()方法来配置MVC中间件。相反,我们需要使用UseRouting()和UseEndpoints()方法来配置路由和端点。
以下是示例代码,在Startup.cs文件中的Configure方法中:
public void Configure(IApplicationBuilder app) { app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
在上面的示例中,我们首先使用UseRouting()方法来启用路由。然后,我们使用UseEndpoints()方法来配置端点并映射控制器路由。在这个例子中,我们将默认路由映射到HomeController的Index动作。