1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

IIS Rewrite with angular app and application alas

Discussão em 'Angular' iniciado por Gruneich3, Outubro 11, 2024.

  1. Gruneich3

    Gruneich3 Guest

    here is the scenario. I have an angular app and a .net 8 web api hosting on IIS. the .net wep api is added to the site as a application with "dotnet" as the alias

    I need domain.com/dotnet to pass through but everything else to get rewrite to ./index.html

    when I go to domain.com/dotnet/someRequest the server just redirects to the angualr app instead of giving me the json data from the api.

    this is my current IIS rewrite rule

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="Angular Routes" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{QUERY_STRING}" pattern=".*/dotnet/*" negate="true" />
    <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>
    </configuration>


    Ive also tried this

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="DOTNET" stopProcessing="true">
    <match url=".*/dotnet/*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="UNENCODED_URL" appendQueryString="false" />
    </rule>
    <rule name="Angular Routes" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <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>
    </configuration>


    if I remove all the rewrite rules then i can get to domain.com/dotnet/getRequest and it will return the json data and i can get to the angualar app by going to domain.com.

    HOWEVER if I refresh the page and my url is like domain.com/homepage then IIS cant find the page.

    my goal to pass all domain.com/dotnet/* request through and everything else to get rewrite to ./index.html to avoid the refresh issue.

    Any help would be greatly apricated!!

    Continue reading...

Compartilhe esta Página