C# 向MVC5项目添加Web API(API接管)
为了给我当前的MVC项目添加一个Web API,我浏览了所有的stack-over-flow QA和在线教程 WebAPI可以工作,MVC只有在我将路由路径放入url时才能工作 我希望MVC路由成为默认路由,但出于某种原因,它总是尝试执行API逻辑 我希望这是我错过的简单的事情 我到目前为止所做的一切 Web API配置类C# 向MVC5项目添加Web API(API接管),c#,asp.net-web-api,asp.net-web-api-routing,C#,Asp.net Web Api,Asp.net Web Api Routing,为了给我当前的MVC项目添加一个Web API,我浏览了所有的stack-over-flow QA和在线教程 WebAPI可以工作,MVC只有在我将路由路径放入url时才能工作 我希望MVC路由成为默认路由,但出于某种原因,它总是尝试执行API逻辑 我希望这是我错过的简单的事情 我到目前为止所做的一切 Web API配置类 protected void Application_Start() { AreaRegistration.RegisterAllAreas();
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
默认情况下,没有真正改变任何东西
MVC配置类
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
默认情况下,没有真正改变任何东西
全局配置类
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
API控制器类
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
默认情况下,没有真正改变任何东西
这就是我得到的错误
我似乎无法设置默认路由或从MVC等开始…请检查属性->launchSettings.json文件。应该能够在那里配置启动url。asp.net 5是指.net核心吗?@ChrisCooper show home controller?您需要将启动项目设置为多个。右键单击您的解决方案>属性>公共属性>启动项目选择多个,然后为您的MVC和API项目设置要启动的操作。Hi Max It Core,我似乎没有launchSettings.json文件。恩科西。我将编辑问题并添加主控制器。jomsk13。我无法运行多个项目,因为API和MVC在一个项目中,但thanktI似乎无法设置默认路由或以MVC等开始…请检查属性->launchSettings.json文件。应该能够在那里配置启动url。asp.net 5是指.net核心吗?@ChrisCooper show home controller?您需要将启动项目设置为多个。右键单击您的解决方案>属性>公共属性>启动项目选择多个,然后为您的MVC和API项目设置要启动的操作。Hi Max It Core,我似乎没有launchSettings.json文件。恩科西。我将编辑问题并添加主控制器。jomsk13。我不能运行多个项目,因为API和MVC在一个项目中,但是谢谢
namespace MVCPortal.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}}