我有一个在本地完美运行的 ASP.NET MVC 项目。它有一些继承自 Controller 的 Controller 和一些继承自 ApiController 的 Controller 。我的路线如下。当我在本地通过 Visual Studio 运行该项目时,它运行良好。我可以击中所有端点并获得预期的响应。当我将它部署到云服务器 (Windows Server 2008 r2) 时,只有 :Controller 端点有效(那些位于/p/{controller}/{action} 的端点)。任何端点都没有 :ApiController 工作。我对所有这些都收到以下错误:
{"$id":"1","Message":"No HTTP resource was found that matches the request URI 'http://DOMAIN/CONTROLLER'.","MessageDetail":"No type was found that matches the controller named 'CONTROLLER'."}
我的路线:
在 RouteConfig.cs 中:
routes.MapRoute(
name: "Default",
url: "p/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Redirect", id = UrlParameter.Optional }
);
在 WebApiConfig.cs 中:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}",
defaults: new { }
);
最佳答案
我将代码复制到一个新的 webapi 项目并且它可以工作。这一定是旧项目的某种配置问题,而不是 VM 上缺少依赖项,但我仍然不知道真正的原因是什么。
关于c# - MVC WebApi 端点不适用于生产环境,但常规端点可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16343227/