Asp.net 5 Web.Api+;IIS+;index.html+;角度4
我开始做一个新的水疗项目,并决定使用Angular 4。此外,我还有一个用Asp.Net 5编写的现有后端,并使用Web.Api获取数据。(没有MVC控制器、cshtml等,后端仅用于获取数据!) 我在*.csproj附近创建了新的Angular项目,并放置了Web.config文件(因此这是我网站的根目录) 问题是-Angular将所有文件编译到“dist”文件夹,包括index.html,但是IIS找不到它,因为它的根文件夹比它高一级 我尝试过的:Asp.net 5 Web.Api+;IIS+;index.html+;角度4,asp.net,angular,iis,asp.net-web-api,Asp.net,Angular,Iis,Asp.net Web Api,我开始做一个新的水疗项目,并决定使用Angular 4。此外,我还有一个用Asp.Net 5编写的现有后端,并使用Web.Api获取数据。(没有MVC控制器、cshtml等,后端仅用于获取数据!) 我在*.csproj附近创建了新的Angular项目,并放置了Web.config文件(因此这是我网站的根目录) 问题是-Angular将所有文件编译到“dist”文件夹,包括index.html,但是IIS找不到它,因为它的根文件夹比它高一级 我尝试过的: 设置,然后角度路由器导航到 /dist/*
,然后角度路由器导航到
/dist/*路由路径*
而不是*路由路径*
有人能帮我解决这个问题吗?如果有人感兴趣,我最终使用了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>
如果有人感兴趣,我最终使用了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>
您可以将两个项目都放在一个根域中。通常它对搜索引擎优化很重要。 angular cli应用程序和webapi都将位于同一根文件夹中,url重写将类似于以下内容
<rule name="Angular Routes" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/api" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
您可以将两个项目都放在一个根域中。通常它对搜索引擎优化很重要。 angular cli应用程序和webapi都将位于同一根文件夹中,url重写将类似于以下内容
<rule name="Angular Routes" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/api" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>