2016-04-24 33 views
1

我想发布我的项目到IIS中的一个文件夹,但路径设置的方式是我看起来像一个内部循环,没有找到路径。发布我的webapi项目aspnet web api angularjs

enter image description here

我出版了一本文件夹中的项目已经

angular.module("common.services", ["ngResource"]) 

.constant("appSettings", 
{ 
    //serverPath: "http://localhost:53967/" 
    //name of the computer and folder to which the project was published 
    serverPath:"http://ct-dx-ariang/AspNetWebApi/" 
}); 

而且具有资源设置为跟随

angular.module("common.services").factory("productResource", ["$resource", "appSettings", productResource]) 

function productResource($resource, appSettings) { 

    //return $resource(appSettings.serverPath + "/api/products/:search"); 
    return $resource(appSettings.serverPath + "/api/products/:id" 

这是我的路线

$urlRouterProvider.otherwise("/");//default url 
     $stateProvider.state("home", { 
      url: "/", 
      templateUrl: "/templates/welcomeView.html" 
     }).state("productList", { 
      url: "/products", 
      templateUrl: "/templates/productListView.html", 
      controller: "ProductListController" 
     }). 

如何修改此示例项目,以便它在IIS上的发布文件夹中运行,而不是在Visual Studio上的localhost中运行?

回答

2

路径开始处的斜杠使该路径相对于站点的根。所以你的情况:

templateUrl: "/templates/productListView.html" 

总是引用http://myhostname/templates/productListView.html,无论在哪个子路径托管网站。

除去第一斜线可以解决您的问题:

templateUrl: "templates/productListView.html" 

而且看你的$resource配置:

return $resource(appSettings.serverPath + "/api/products/:id" 

而且你AppSettings常数:

serverPath:"http://ct-dx-ariang/AspNetWebApi/" 

在我看来,您要为您的$resource路径添加两个连续的斜杠。由此产生的路径将为:http://ct-dx-ariang/AspNetWebApi//api/products/:id

1

这是我的路线

漂亮的硬编码。确保你在那里为你所有的模板使用相同的常量。

templateUrl: appSettings.serverPath + "/templates/welcomeView.html"