【问题标题】:http://localhost/myapp/assets/i18n/en.json not found when angular 6 code deployed on windows 7 IIS server在 Windows 7 IIS 服务器上部署 Angular 6 代码时找不到 http://localhost/myapp/assets/i18n/en.json
【发布时间】:2020-07-08 03:41:35
【问题描述】:

我正在尝试将我的应用程序部署到 Windows 7 PC 上的 IIS 服务器。网址是

http://localhost/myapp

  1. 我安装了 URL 重写。
  2. 这是我的 web.config 内容

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
       <action type="Rewrite" url="/MyApp/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

我的应用程序在我的计算机上使用“ng serve”运行得非常好。当我在 Windows 7 PC 上部署 IIS 时,应用程序无法访问图像、json 文件等资源。我收到 404 错误。我认为我的 web.config 文件有问题。文件 en.json 在部署后位于 c:\inetpub\wwwroot\myapp\assets\i18n 文件夹。 请帮忙。

【问题讨论】:

  • 在 IIS 中是否有默认网站映射到 c:\inetpub\wwwroot\myapp 目录?请分享您如何在 IIS 中设置 Angular6 应用程序的详细信息
  • 听起来你需要将base href 标签设置为/myapp angular.io/guide/deployment#base-tag
  • 应用映射到c:\inetpub\wwwroot\myapp。 base_href 是“/myapp/”。

标签: angular iis url-rewriting


【解决方案1】:

问题在于 IIS 7 没有“.json”作为默认文件扩展名。这是 web.config 添加“.json”。

<configuration>
<system.webServer>
        <security>
            <requestFiltering>
                <fileExtensions>
                    <add fileExtension=".json" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <staticContent>
            <remove fileExtension=".json" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
</system.webServer>
</configuration>

“.json”文件扩展名是 ISS 8 中的默认扩展名。我必须在添加之前将其删除。

【讨论】:

  • 我搜索了所有其他相关文章,代码没有问题。我只是在 web.config 中缺少上述 mime 类型配置,它使我免于托管环境 (Azure) 上的 404 错误。当我在本地/调试环境上运行它时,我没有遇到任何问题。
【解决方案2】:

改变 o Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

 

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="./index.html" />
      </rule>
    </rules>
  </rewrite>
   <security>
            <requestFiltering>
                <fileExtensions>
                    <add fileExtension=".json" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <staticContent>
            <remove fileExtension=".json" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
</system.webServer>

 

</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2018-05-03
    • 2021-01-14
    • 1970-01-01
    相关资源
    最近更新 更多