2

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.

MikeGsus
  • 170
  • 1
  • 2
  • 12

2 Answers2

3

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>
MikeGsus
  • 170
  • 1
  • 2
  • 12
1

In your web.config change <action type="Rewrite" url="/FIN360" /> and in your index.html from the <base href="/"> remove the / Try this else change <base href="./"> OR <base href="/FIN360">

Vaibhav
  • 1,481
  • 13
  • 17
  • Do I deploy with `ng build --prod`, whitout `--base-href=/FIN360/`? – MikeGsus Aug 02 '18 at 20:20
  • I get the same message: 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. – MikeGsus Aug 02 '18 at 21:31
  • build it with ng build --prod -base-href=/FIN360 and do restart your application pool in iis and post that do the rewuest in incognito window or clear the cache of the browser. – Vaibhav Aug 03 '18 at 04:36
  • I did it, but I've a new problem, like this: [link to question](https://stackoverflow.com/questions/32184300/iis-configuration-for-using-angular-ui-routing-html5mode) – MikeGsus Aug 06 '18 at 20:08
  • @MikeGsus I have answered on that question itself – Vaibhav Aug 07 '18 at 03:05