I'm using ASP.NET 5 where the entire folder structure is changed and the web.config is replaced (compared to previous ASP.NET versions). I'm doing client side routing using angularJS and I have this route:
.when('/movies/add', {
templateUrl: '/Views/add.html',
controller: 'MoviesAddController'
})
Everything works as longs as I start on my index.html and click on a link to /movies/add. If I reload the page using the /movies/add URL, the server gives me a 404. According to this tutorial I should do a rewrite in web.config, like this:
<!-- from http://stackoverflow.com/questions/25916851/wrapping-staticfilemiddleware-to-redirect-404-errors -->
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<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>
</system.webServer>
</configuration>
I am using IIS Express 10.0 (in Windows 10 preview). I understand that the part in web.config should still exist in ASP.NET 5 to configure IIS but I don't get any result from this. Do I need to do something different using IIS Express? Is there another, more general, solution provided in ASP.NET 5?
Thanks!
The concept of URL rewriting is simple. When a client sends a request to the Web server for a particular URL, the URL rewriting module analyzes the requested URL and changes it to a different URL on the same server.
web.config
is still supported but it should go into wwwroot
folder. You may be missing Url Rewrite module for IIS.
Alternatively, you can write a custom OWIN middleware to support html5 routing mode.
See this for an example: http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With