本文介绍了MapControllerRoute,MapDefaultControllerRoute和MapControllers之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将.NET Core 2.1升级到.NET Core 3.0,并且看到此处我必须使用 UseEndpoints .但是,在某些页面上,我使用 MapControllerRoute MapDefaultControllerRoute MapControllers 看到了它.

I'm upgrading .NET Core 2.1 to .NET Core 3.0 and I saw here I have to use UseEndpoints. However, at some pages I've seen it with either MapControllerRoute, MapDefaultControllerRoute, or MapControllers.

我在文档,我发现 MapDefaultControllerRoute MapControllerRoute("default","{controller = Home}/{action = Index}/{id?}"基本上相同.但是我不理解与 MapControllers 的区别.最后一个功能实际上是做什么的?该文档说:将控制器操作的端点添加到IEndpointRouteBuilder而不指定任何路由.",但抱歉,我不明白.

I checked at the documentation and I saw that MapDefaultControllerRoute is basically the same as MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"). But I don't understand the difference with MapControllers. What does this last function actually do? The documentation says: "Adds endpoints for controller actions to the IEndpointRouteBuilder without specifying any routes.", but I don't get it, sorry.

推荐答案

MapControllers 用于映射控制器上可能存在的任何属性,例如 [Route] [HttpGet]

MapControllers is used to map any attributes that may exist on the controllers, like, [Route], [HttpGet], etc.

这篇关于MapControllerRoute,MapDefaultControllerRoute和MapControllers之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 17:10