Difference between `MapControllerRoute`, `MapDefaultControllerRoute`, and `MapControllers`?

谁都会走 提交于 2020-12-05 05:00:27

问题


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.

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.


回答1:


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



来源:https://stackoverflow.com/questions/59107064/difference-between-mapcontrollerroute-mapdefaultcontrollerroute-and-mapco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!