我使用Visual Studio 2015在ASP .NET 5中構建Web應用程序。我創建了一個包含數據訪問,業務,服務和用戶界面層的解決方案。 我已經引用了用戶界面層中的服務。由於在MVC 6中Web API和MVC都屬於同一個項目模板,因此有必要爲服務和UI提供兩個不同的層,或者使用不同控制器的相同項目就足夠了。ASP.NET中的Web應用程序5
而且也是在UI項目,我已經註釋掉在Startup.cs
services.AddWebApiConventions();
routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
以下線在運行的項目,主頁出現罰款,但是當我點擊在主頁的URL鏈接改變這樣的
http://localhost:45075/api/Home
,它給錯誤頁面說
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied.
Sample.Services.Controllers.HomeController.Index
Sample.Services.Controllers.HomeController.About
Sample.Services.Controllers.HomeController.Contact
Sample.Services.Controllers.HomeController.Error
我理解是,因爲我支持Web API約定,它要服務的家庭控制器具有路由屬性
[Route("api/[controller]")]
如果是如何通過指定命名空間或解決這一衝突的一些限制,同時呈現在路線的意見。
我是初學者。糾正我,如果我錯了。
請嘗試每個帖子提出一個問題,它使得提供有用的答案更容易。話雖如此,你需要使用約定或顯式映射,而不是兩者。 – Claies 2015-02-10 14:22:20