【问题标题】:URL's Path are not working when deployed to IIS Server System部署到 IIS 服务器系统时,URL 的路径不起作用
【发布时间】:2020-02-06 09:39:03
【问题描述】:

我有一个问题,当我将我的 ASP.NET MVC 项目部署到 IIS 服务器系统时,图像 url 从 CSS 添加它们没有采用确切的路径,并且在 Angularjs 中无法发送帖子或获取请求。

CSS 示例代码

<div class="container" style="background-image:url('../../Images/img/product-1.jpg')">
    <div class="text-left">Welcome</div>
</div>

AngularJS 示例代码

var app=angular.module('myApp', ['ngRoute']);
app.controller('myCtrl', ['$scope', '$http', function($scope, $http){
    $http({
         method:"POST",
         url:"/controller/action",
         data:{id:1}
    }.then(function(response){
           console.log(response)
      }, function(error){
          console.log(error)
     });
]});

所以这些是我在项目中编写的示例代码。 我有搜索互联网我找到了一些解决方案,例如

  1. 通过添加或删除 IIS 功能安装 StaticContent
  2. 更改应用程序池以进行身份​​验证。
  3. 删除 web.config 中的 staticContent 标签。

我晚上试过这些东西我无法解决我的问题。

我的错误是:

GET http://18.xxx.xxx.xxx/controller/action 404(未找到)

GET http://18.xxx.xxx.xxx/Images/img/bg-img/top.jpg404(未找到)

实际网址应该像这样加载

GET http://18.xxx.xxx.xxx/myApplication/controller/action 404(未找到)

GET http://18.xxx.xxx.xxx/myApplication/Images/img/bg-img/top.jpg 404(未找到)

【问题讨论】:

    标签: css angularjs asp.net-mvc iis


    【解决方案1】:

    更改以下样式中提到的样式。 备注:直接改关卡。

    <div class="container" style="background-image:url('~/Images/img/product-1.jpg')">
    <div class="text-left">Welcome</div>
    

      <div class="container" style="background-image:url('@Url.Content("~/Images/img/product-1.jpg")')">
    <div class="text-left">Welcome</div>
    

    解释~ vs /:

    / - 站点根目录

    ~/ - 应用的根目录

    【讨论】:

    • 感谢回复,但它不起作用> 18.xxx.xxx.xxx/home/~/Images/img/bg-img/… 错误消息显示如下
    • 嗨,请告诉我图像位置的层次结构是什么?
    • 我的位置路径是C:/inetpub/wwwroot/myapplication/Images/img/bg-img/imge.jpg 所以我已经部署到默认网站/我的应用程序
    • 去掉 ~ ,然后检查。
    • 不,它不工作,我也喜欢这个../../../images/img/imge.jpg 它不能从根文件夹中选择
    猜你喜欢
    • 2022-11-22
    • 2022-12-15
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    相关资源
    最近更新 更多