问题
i have enabled the html5mode to remove Hashing from web url,after that i get an error.so i have mentioned the base href in master page. set rewrite url in web config.
when i goes into state view page and refresh the page it will show the wrong url.when launch the application in iis 7.5 getting error.
for that i have rewrite the url.
<rewrite>
<rules>
<rule name="RewriteRules stopProcessing="true">
<match url=".*"/>
<conditions logicalGrouping="MatchAll">
<add input ="{REQUEST_FILEName}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILEName}" matchType="IsDirectory" negate="true"/>
<add input ="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="home/home"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Can anyone helpme
回答1:
when you enable html5mode, your all request should redirected to your main url (where your application start ex. home/index). try add below code in the RegisterRoutes method
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default1",
url: "{*.}",
defaults: new
{
controller = "Home",
action = "Index",
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
来源:https://stackoverflow.com/questions/37339306/angular-js-strange-issue-ui-router-html5mode-enabled-page-refresh-issue-in-mvc-5