更新时间:2021-09-07 21:48:18
就我而言,在花了将近 30 分钟试图解决问题后,我找到了导致它的原因:
In my case after spending almost 30 minutes trying to fix the problem, I found what was causing it:
我在 WebApiConfig.cs
中定义的路由是这样的:
My route defined in WebApiConfig.cs
was like this:
config.Routes.MapHttpRoute(
name: "ControllersApi",
routeTemplate: "{controller}/{action}"
);
它应该是这样的:
config.Routes.MapHttpRoute(
name: "ControllersApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
如您所见,它干扰了 RouteConfig.cs
中定义的标准路由.
as you see it was interfering with the standard route defined in RouteConfig.cs
.