【问题标题】:Angular Js Strange issue Ui Router Html5mode enabled page refresh issue in mvc 500 errorAngular Js Strange 问题 Ui Router Html5mode 在 mvc 500 错误中启用页面刷新问题
【发布时间】:2016-05-20 06:21:30
【问题描述】:

我已启用 html5mode 以从 web url 中删除散列,之后我收到一个错误。所以我在母版页中提到了基本 href。在 web config 中设置重写 url。

当我进入状态视图页面并刷新页面时,它将显示错误的 url。当在 iis 7.5 中启动应用程序时出现错误。

为此我重写了网址。

<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>

谁能帮帮我

【问题讨论】:

标签: angularjs asp.net-mvc asp.net-mvc-4 angular-ui-router iis-7.5


【解决方案1】:

当您启用 html5mode 时,您的所有请求都应重定向到您的主 url(您的应用程序开始的位置,例如 home/index)。尝试在 RegisterRoutes 方法中添加以下代码

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 }
            );
        }

【讨论】:

  • 所以我不需要重写 webconfig 中的 url 和布局中的 base href 吗?足够多地提到路由配置。
猜你喜欢
  • 2015-08-05
  • 1970-01-01
  • 2019-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2021-12-31
相关资源
最近更新 更多