一个解决方案中的两个项目

问题描述:

我的Visual Studio解决方案中有两个项目。一个是带有AngularJS和html前端的空WEB API应用程序。其他是带有嵌入式数据库,控制器和东西的WEB API项目。问题是当我从我的第一个解决方案调用web api控制器时,我没有找到404。我怀疑在托管中存在问题,但我完全不知道是什么类型。我试图在IIS中托管后端项目,但没有结果。也许有一些我错过了。一个解决方案中的两个项目

+0

为什么你需要两个分离的解决方案?将所有东西放在一起并不容易? – 2014-09-26 09:32:20

+0

我有一个解决方案,其中有两个项目 – 2014-09-26 10:01:56

+0

是Global.ascx或启动类有添加的路线!你可以在那里展示代码吗? – satish 2014-09-26 10:05:56

花费在研究这个有很多的时间后,我意识到,这是与本地主机不同端口的问题,解决方案可以在此找到:http://jaliyaudagedara.blogspot.com/2014/08/angularjs-consuming-aspnet-web-api.html

基本上我应该改变属性中的项目URL以匹配前端项目的localhost端口并添加一个'api'后缀以避免两个项目使用相同的虚拟目录。

@satish, 的Global.asax:

namespace WebAPI_Training 
{ 
public class WebApiApplication : System.Web.HttpApplication 
{ 
    protected void Application_Start() 
    { 
     GlobalConfiguration.Configure(WebApiConfig.Register);    
    } 
} 
} 

WebApiConfig.cs:

namespace WebAPI_Training 
{ 
public static class WebApiConfig 
    { 
     public static void Register(HttpConfiguration config) 
     { 
      // Web API configuration and services   

     // Web API routes 
     config.MapHttpAttributeRoutes(); 

     config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "api/{controller}/{action}/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 

     var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First(); 
     jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); 
    } 
} 
}