IIS 服务器中的角度路由 [英] Angular Routing in IIS server

查看:25
本文介绍了IIS 服务器中的角度路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IIS 服务器中有一个 Angular 4 应用程序,在同一台服务器中有一个 .NET Web API.它们位于不同的文件夹中:angular 应用程序位于/wwwroot/angular/"中,而 web api 位于/wwwroot/api/"中.当我向 web api 发出请求时,它成功运行,但是当我尝试使用 angular 应用程序中的路由模块导航到与 index.html 不同的 URL 时,我收到此消息:

500内部服务器错误.您要查找的资源有问题,无法显示.

此外,我有两个 Web.Config 文件 - 每个文件夹中一个 -.

我的 Angular Web.配置为:

<重写><规则><规则名称="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"/></条件><action type="重写" url="/index.html"/></规则></规则></rewrite></system.webServer>

WEB API 的Web.config

<预><代码><配置><system.webServer><处理程序><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"/></处理程序></system.webServer></配置>

我研究了一些问题,例如:

stackoverflow.com/questions/49833141/blank-page-when-publishing-angular-5-net-core-web-api

stackoverflow.com/questions/42865084/redirect-unknown-requests-to-index-html-in-springboot

但它们对我不起作用.

任何人都可以帮助我.

提前致谢.

解决方案

解决方案是将所有 Angular 文件移动到 root,在 index.html 我离开了 <base href="/"> 并使 web.config 像这样:

I have an Angular 4 app in a IIS server, in the same server there is a .NET Web API. They are in diferents folders: angular app is in "/wwwroot/angular/" and web api in "/wwwroot/api/". When I do a request to web api, it works successfully, but when I try to navigate to an URL different to index.html using the Routing Module in angular app I get this message:

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.

Also, I have two Web.Config files -one in each folder-.

My Angular Web. Config is:

<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>

Web.config of WEB API

<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>

I researched in some questions like:

stackoverflow.com/questions/49833141/blank-page-when-publishing-angular-5-net-core-web-api

and

stackoverflow.com/questions/42865084/redirect-unknown-requests-to-index-html-in-springboot

But they doesn't work to me.

Anybody help me on this.

Thanks in advance.

解决方案

The solution was move all the Angular files to root, at index.html I left <base href="/"> and make the web.config like this:

<?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 服务器中的角度路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆