angularjs - New route re-writes URL to default route, SignalR stops connecting
问题描述
I've attempted to add a route in RouteConfig.cs
called 'CustRoute', the only other route present is the default route.
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "CustRoute",
url: "{cust}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { cust = new CustConstraint() }
).RouteHandler = new CustMvcRouteHandler();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
The URL reverts back to the default one when loading the page. The page loads but I cannot connect to SignalR either.
For example, if I go to www.example.com/Cust/Home
it will change the URL to www.example.com/Home
on loading the page.
解决方案
经过进一步调查,我解决了这个问题,它是ngRoute
在 AngularJS 代码中导致问题的,因为元素中的 HTML<base>
标记在我的 URL 中<head>
没有考虑。/Cust/
ngRoute 使用<base>
标签来路由 URL(信息归功于这个答案)。
我通过更改<base href="@(Request.ApplicationPath)"/>
为<base href="@(Request.ApplicationPath + "/" + custName)"/>
.
推荐阅读
- c# - 存在哪些 System.Windows.Forms.Design 编辑器?
- sql - 为什么这个 sql 查询运行这么慢?带有详细字符串过滤器的大表
- python - python中的符号“\”是什么意思?
- php - 嗨,我在 Laravel 编码,我想访问其中的 $request 变量
- php - PHP sqlsrv 批量插入不完整
- angular - 架构验证失败并出现以下错误:数据路径“.builders['app-shell']”应该具有必需的属性“类”。错误:
- gnu-parallel - Ubuntu 18.04:GNU 并行无法在本地系统上找到并使用全部内核数
- python - python - 密码学包 - 导入错误
- jquery - sharepoint online - 如何检索具有多个用户的人员列...需要有关所有可用选项的信息
- bash - 在 SED 命令中插入变量的内容