3

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.

3
  • can you post your Route file in Webapi ? Commented Aug 2, 2018 at 17:54
  • 1
    You need to redirect every request except the assets like images etc. to the index.html. Commented Aug 2, 2018 at 17:54
  • @Niladri I edited my post. Commented Aug 2, 2018 at 18:02

2 Answers 2

4

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>
Sign up to request clarification or add additional context in comments.

Comments

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

5 Comments

Do I deploy with ng build --prod, whitout --base-href=/FIN360/?
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.
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.
I did it, but I've a new problem, like this: link to question
@MikeGsus I have answered on that question itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.