Angular IIS 服务器中的路由
Angular Routing in IIS server
我在 IIS 服务器中有一个 Angular 4 应用程序,在同一服务器中有一个 .NET Web API。它们在不同的文件夹中:angular 应用程序在“/wwwroot/angular/”中,网络 api 在“/wwwroot/api/”中。当我向网络 api 发出请求时,它成功运行,但是当我尝试使用 angular 应用程序中的路由模块导航到与 index.html 不同的 URL 时,我得到此消息:
此外,我有两个 Web.Config 个文件 - 每个文件夹一个 -。
我的 Angular 网站。配置为:
<system.webServer>
<rewrite>
<rules>
<rule name="Angular 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="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
WEBWeb.configAPI
<configuration>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
我研究了一些问题,例如:
whosebug.com/questions/49833141/blank-page-when-publishing-angular-5-net-core-web-api
和
但它们对我不起作用。
任何人都可以帮助我。
提前致谢。
在您的 web.config 中更改 <action type="Rewrite" url="/FIN360" />
并在您的 index.html 中从 <base href="/">
删除 / 试试这个其他更改<base href="./">
或 <base href="/FIN360">
解决方案是将所有 Angular 文件移动到根目录,在 index.html 我离开 <base href="/">
并使 web.config 像这样:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="^(.*)$" />
</rewriteMaps>
<rules>
<rule name="Angular Route" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="/api(.*)$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="?" />
</authorization>
</security>
</system.webServer>
</configuration>
我在 IIS 服务器中有一个 Angular 4 应用程序,在同一服务器中有一个 .NET Web API。它们在不同的文件夹中:angular 应用程序在“/wwwroot/angular/”中,网络 api 在“/wwwroot/api/”中。当我向网络 api 发出请求时,它成功运行,但是当我尝试使用 angular 应用程序中的路由模块导航到与 index.html 不同的 URL 时,我得到此消息:
此外,我有两个 Web.Config 个文件 - 每个文件夹一个 -。
我的 Angular 网站。配置为:
<system.webServer>
<rewrite>
<rules>
<rule name="Angular 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="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
WEBWeb.configAPI
<configuration>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
我研究了一些问题,例如:
whosebug.com/questions/49833141/blank-page-when-publishing-angular-5-net-core-web-api
和
但它们对我不起作用。
任何人都可以帮助我。
提前致谢。
在您的 web.config 中更改 <action type="Rewrite" url="/FIN360" />
并在您的 index.html 中从 <base href="/">
删除 / 试试这个其他更改<base href="./">
或 <base href="/FIN360">
解决方案是将所有 Angular 文件移动到根目录,在 index.html 我离开 <base href="/">
并使 web.config 像这样:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="^(.*)$" />
</rewriteMaps>
<rules>
<rule name="Angular Route" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="/api(.*)$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="?" />
</authorization>
</security>
</system.webServer>
</configuration>