Open Closed

Removing hash (#) from URL not working #6642


0
firnas created

We are trying to remove the # from url in MVC angularjs project. Below steps we followed

  1. Add $locationProvider.html5Mode(true); in app.js
  2. Add in layout.cshtml

After these changes we can able to remove the # from url. Application works fine as SPA. But when reload the page that giving below error.

Server Error in '/' Application The resource cannot be found. HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

To fix this we added below rewrite rule in web.config

This giving too_many_redirects issue.

To over come from this we added below routing rule in routeConfig.cs

       routes.MapRoute(
       name: "Default",
       url: "{*url}",
       defaults: new { controller = "Home", action = "Index" },
       namespaces: new[] { "NetScribe.Web.Controllers" });

But this also not helping.

Please help with any working methods to achieve this.


3 Answer(s)
  • 0
    ismcagdas created
  • 0
    firnas created

    Thanks. But the problem here is the error when reloading the page (by F5 or refresh icon click)

  • 0
    maliming created

    @firnas Have you tried this solution? http://www.advancesharp.com/blog/1191/angularjs-html5-mode-reloading-page-not-found-solution