Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Removing hash (#) from URL not working #6642


User avatar
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 <base href="/"> 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

<rewrite> <rules> <rule name="Main Rule" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/" /> </rule> </rules> </rewrite>

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)