2017-07-27 56 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>