We are trying to remove the # from url in MVC angularjs project. Below steps we followed
- Add $locationProvider.html5Mode(true); in app.js
- 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)
-
0
-
0
Thanks. But the problem here is the error when reloading the page (by F5 or refresh icon click)
-
0
@firnas Have you tried this solution? http://www.advancesharp.com/blog/1191/angularjs-html5-mode-reloading-page-not-found-solution