在IIS上设置Angular深层链接 [英] Setting up Angular deep linking on IIS
问题描述
我正在尝试在IIS上配置Angular / ASP.NET 5应用程序以支持深层链接,以便诸如domain.com/article/title-slug之类的URL工作
I'm trying to configure an Angular/ASP.NET 5 application on IIS to support deep linking, so that a URL such as domain.com/article/title-slug works
我使用IIS重写模块将以下代码添加到我的web.config中:
I've added the following code to my web.config using the IIS rewrite module:
<rewrite>
<rules>
<rule name="redirect all" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="wwwroot/index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
我的问题是我的网站不再加载,我的网页标签中没有任何内容没有来源。
My problem is that my site no longer loads, I have a blank screen with nothing in the network tab and no source.
我的inetpub \site \文件夹是dotnet核心发布文件夹的根目录,我在inetput \site \\中有角度构建资产\\ www.root
My inetpub\site\ folder is the root of the dotnet core publish folder, and I have the angular build assets within inetput\site\wwwroot
我的基础href是=/,一切正常,没有重写代码。
My base href is = "/" and everything works fine without the rewrite code.
最后,我尝试将我的重写URL更改为
Finally, I tried changing my rewrite URL to
<action type="Rewrite" url="/index.html" appendQueryString="true" />
然后我开始收到错误:
inline.f137c7f1f4e2a52a2fb9.bundle.js:1 Uncaught SyntaxError: Unexpected token <
polyfills.25e42e2a7a0746e9ff75.bundle.js:1 Uncaught SyntaxError: Unexpected token <
main.0d9f8e7be2ccd1472551.bundle.js:1 Uncaught SyntaxError: Unexpected token <
推荐答案
我最终通过废弃URL重写模块来修复此问题并在代码中处理:
I ended up fixing this by scrapping the URL rewrite module and handling this in code:
app.Run(async (context) =>
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "index.html"));
});
这篇关于在IIS上设置Angular深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!