Search code examples
angularjsasp.net-mvc-5dnx

ASP.NET 5 and Angular Routing not working on dnx rc1


Hi I have a project built in ASP.NET 5 (dnxcore50 and dnx451). It is serving the requests for my AngularJS scripts. When I built the project I was using the Microsoft beta 5 dependencies and using a rewrite rule to send all the requests to index.html and so my angular routing would work just fine. But today I had to upgrade to the rc1 dependencies and now my rewrite is not working and I'm just getting a 404 on my route. This new libraries added this weird lines of code to my web.config

  <handlers>
  <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />

Is there a way how can I set my routing so that it works with angular for example if I go to localhost/shop it will redirect it to index.html and my angular routing will take over.


Solution

  • I am on similar setup and I have in Configure in Startup.cs,

        app.UseDefaultFiles();
    
        app.UseStaticFiles();
    
        app.UseIISPlatformHandler();
    

    and a rewrite rule in system.webServer in web.config, needed that to be able to have both web api and index.html angular app served:

        <rewrite>
          <rules>
            <!--Redirect selected traffic to index -->
            <rule name="Index Rule" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
              </conditions>
              <action type="Rewrite" url="/index.html" />
            </rule>
          </rules>
        </rewrite>
    

    You may need something similar too with your own rules