URL rewrite in ASP.NET 5

I use ASP.NET 5, where the entire folder structure is changed and replaced by web.config (compared to previous versions of ASP.NET). I am doing client-side routing using angularJS and I have this route:

.when('/movies/add', { templateUrl: '/Views/add.html', controller: 'MoviesAddController' }) 

Everything works as long as I start with my index.html and click on the link to / movies / add. If I reload the page using the / movies / add URL, the server gives me 404. According to this tutorial, I have to rewrite it in web.config, for example:

 <!-- 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 preview of Windows 10). I understand that the part in web.config must still exist in ASP.NET 5 to configure IIS, but I am not getting any result from this. Do I need to do something using IIS Express? Is there any other, more general solution provided in ASP.NET 5?

Thanks!

+6
source share
1 answer

web.config is still supported, but it should go into the wwwroot folder. You may be missing the Url Rewrite module for IIS.

Alternatively, you can write custom OWIN middleware to support the html5 routing mode.

See an example: http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx

+6
source

Source: https://habr.com/ru/post/989423/


All Articles