2017-07-27 59 views
1

我开始研究一个新的SPA项目,并决定使用Angular 4.另外,我有一个现成的后端,写在Asp.Net 5并使用Web.Api来获取数据。 (没有MVC控制器,cshtml等,后端仅用于获取数据!)Asp.net 5 Web.Api + IIS + index.html + Angular 4

我在* .csproj附近创建了新的Angular项目,并放置了Web.config文件(所以这是我的网站的根目录)。

问题是 - Angular将所有文件编译到“dist”文件夹,包括index.html,但IIS无法找到它,因为它的根文件夹高一级。

我曾尝试:

  1. 设置<base href="/dist/">,但随后角路由器导航到 /dist/*route_path*,而不是*route_path*

  2. 设置IIS defaultDocument为 “/dist/index.html”但随后所有的捆绑包都发现一个不是 (404),因为它试图在index.html附近找到它们。

  3. 弹出Angular webpack配置并编辑它以达到我的目标。我将 “Index.html”更改为“../Index.html”,并且我已经与 捆绑软件一起使用html,* .css文件中的位网址无效..我无法使其所有前缀 都加上“/ dist /“

有人可以帮我弄清楚吗?

回答

0

如果有人有兴趣,我结束了IIS URL重写模块如下:

<system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="site"> 
      <match url="(.*)" /> 
      <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_URI}" pattern="^/api" negate="true" /> 
      <add matchType="IsFile" pattern="^/images/" negate="true" /> 
      <!-- the rest of your rules here... --> 
      </conditions> 
      <action type="Rewrite" url="/dist/{R:1}" /> 
     </rule> 
     </rules> 
    </rewrite> 
</system.webServer>