我剛將一個現有的API項目合併到另一個現有的MVC項目中。 API控制器與MVC控制器具有相同的名稱,但它們位於2個不同的名稱空間中(分別爲MyApp.Web.MyController和MyApp.API.MyController)。在同一個項目中爲MVC和API配置路由
現在,我真的不知道如何路由配置,這樣我可以訪問API控制器:(
我看到這篇文章:Mixing Web Api and ASP.Net MVC Pages in One Project和希望達到什麼樣的@Mike沃森認爲有,但我不知道該如何配置路由
這是我目前在RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
最簡單的方式來創建新的項目與API和mvc比較。你將能夠看到如何配置 – Uriil
謝謝!我添加了WebApiConfig.cs到MVC項目,並從Global.asax.cs添加了對它的調用。這似乎現在:)。 – AngieM