Angular Js Strange issue Ui Router Html5mode enabled page refresh issue in mvc 500 error

你。 提交于 2019-12-25 07:03:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!