【问题标题】:Publish my webapi project aspnet web api angularjs发布我的 webapi 项目 aspnet web api angularjs
【发布时间】:2016-08-17 17:36:29
【问题描述】:

我想将我的项目发布到 IIS 中的一个文件夹,但是通过设置路由的方式,我得到了一个看起来像内部循环的东西,但没有找到路径。

我已经在一个文件夹中发布了项目

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 中运行?

【问题讨论】:

    标签: angularjs iis asp.net-web-api


    【解决方案1】:

    路径开头的斜线使该路径相对于站点的根目录。所以在你的情况下:

    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

    【讨论】:

      【解决方案2】:

      这些是我的路线

      相当硬编码。确保您对所有模板也使用相同的常量。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-13
        • 2019-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        相关资源
        最近更新 更多