IIS服务器中的角路由

时间:2018-08-02 17:45:33

标签: asp.net angular iis web-config

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

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

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

我的Angular Web。配置为:

<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 API的Web.config

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

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

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

但是它们对我不起作用。

有人在这方面帮助我。

谢谢。

2 个答案:

答案 0 :(得分:1)

在您的web.config中更改<action type="Rewrite" url="/FIN360" />,并从<base href="/">中的index.html中删除 / ,然后尝试进行其他更改<base href="./">或{{1 }}

答案 1 :(得分:0)

解决方案是将所有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>