I am using angularJS with ASP.NET
. When I run my Web application, all links are working and there is no 500 error.
But when I refresh page I got 500 e
The issue is related to improperly set server
side. Firstly try to turn off the html5
mode
//$locationProvider.html5Mode(true);
$locationProvider.html5Mode({enabled: false});
And check that after refresh all is working. It should.
Change the routing like this:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("fonts*.woff");
routes.IgnoreRoute("*.js");
routes.IgnoreRoute("*.html");
routes.IgnoreRoute("*.css");
routes.IgnoreRoute("api/*");
routes.MapRoute(
name: "Default",
url: "{dummyController}/{dummyAction}/{dummy1}/{dummy2}/{dummy3}",
defaults: new { controller = "Home", action = "Index"
, dummyController = UrlParameter.Optional
, dummyAction = UrlParameter.Optional
, dummy1 = UrlParameter.Optional
, dummy2 = UrlParameter.Optional
, dummy3 = UrlParameter.Optional
}
);
This should do what we need. Whenever there is anything comming to server:
/api/
(ASP.NET Web API) is also skipped here/somestuff/somepart
is treated as Home/Index
This setting url: "{dummyController}/{dummyAction}/{id}",
makes the above. any part coming from html5mode is treated as a route key "dummyController", "dummyAction", while the Home and Index are passed as controller and action in the defaults: new { controller = "Home", action = "Index" ...
And because your application is expecting some parts of your routing, you should use it like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("fonts*.woff");
routes.IgnoreRoute("*.js");
routes.IgnoreRoute("*.html");
routes.IgnoreRoute("*.css");
routes.IgnoreRoute("api/*");
// keep this application special settings
routes.MapRoute("templates", "templates/{action}.html",
new { controller = "Home", action = "Templates", name = "" }
);
routes.MapRoute("contacts","contacts",
new { controller = "Home", action = "Contacts", id = UrlParameter.Optional }
);
// this should do the job on F5
routes.MapRoute(
name: "Default",
url: "{dummyController}/{dummyAction}/{dummy1}/{dummy2}/{dummy3}",
defaults: new { controller = "Home", action = "Index"
, dummyController = UrlParameter.Optional
, dummyAction = UrlParameter.Optional
, dummy1 = UrlParameter.Optional
, dummy2 = UrlParameter.Optional
, dummy3 = UrlParameter.Optional
}
);
Also check this