Single page app in AngularJS and ASP.Net works fine, but when I refresh my page in the browser I get 404 errors Single page app in AngularJS and ASP.Net works fine, but when I refresh my page in the browser I get 404 errors angularjs angularjs

Single page app in AngularJS and ASP.Net works fine, but when I refresh my page in the browser I get 404 errors


Sounds like your server is not re-writing the urls to the app's base URL.

The URL re-writing needed on the web server is server-dependent. For Apache, you'd use mod_rewrite.

Instead, switch Angular to the "Hashbang mode" (the default) so the urls will all store the local state after the # in the url.

I don't want my apps to require server configuration changes, so I recommend hashbang mode.

See AngularJS docs. See section "Hashbang and HTML5 Modes" The HTML5 mode section describes all the configuration issues needed to support HTML5 mode for the urls.


This awesome dude describes how to fix this here.

In brief:

  1. Remove MVC nugets (unless you use MVC controllers for anything) -you can keep the Web API nugets. Keep WebPages and Razor packages.Also delete MVC controllers and views.
  2. You can keep using .cshtmlfiles with some web.config modifications. You'll need this forbundling.
  3. Finally you add a rewrite rule on web.config to point all urls (excluding content, images, scripts etc) to index.html