Angular和IIS WebApplication(或虚拟目录)

问题描述 投票:5回答:2

我们有一个带有IIS网站和下面的IIS Web应用程序的Web服务器。 Web应用程序的根目录是:http://website/webapplication/。部署后,我在浏览器中收到以下错误:

http://website/app/app.component.html 404(未找到)

app / app.component.html 404(未找到)

我的组件:

@Component({
    selector: "app",
    templateUrl: "./app/app.component.html"
})

文件app.component.html确实不存在于/app/app.component.html下,但确实存在于:/webapplication/app/app.component.html。

所以,我的结论是Angular仅在网站的根目录中有效。在html标题中,我将标记设置为:<base href="/webapplication/">,但这没有帮助。

这似乎是一个正常的设置,我无法相信在Angular中解析的模板失败,我必须遗漏一些东西......有谁知道解决这个问题?

angular iis web-applications angular2-template
2个回答
0
投票

虽然您可以使用Url Rewrite并使其正常工作,但此问题的唯一长期解决方案是使用HashLocationStrategy。

Angular 2.0 router not working on reloading the browser


0
投票

我不能在网上使用大多数关于解决这个问题的建议,我不知道为什么。我玩了设置工具,我开始工作了。这是我用过的:

  • 美国10.0
  • Angular 6.1.0项目
  • 虚拟目录转换为应用程序
  • 应用程序池:没有托管代码

webconfig:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="true" />
    <rewrite>
      <rules>
        <rule name="AngularJS 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/index.html" />
      </rule>
    </rules>
    </rewrite>
  </system.webServer>
</configuration>

我的root index.html文件:

<base href="./">   <---- make sure you have the dot in there!
© www.soinside.com 2019 - 2024. All rights reserved.