ASP.NET 到 url 的核心 MVC 路由,带参数
ASP.NET Core MVC route to url with parameters
我使用 ASP.NET Core 2.1 MVC 创建了一个 Web 应用程序。
目前我在发布应用程序时遇到路由问题。
url 应用程序发布的格式是这样的:https://hostername.com/{some_parameter}
我的应用程序生成的所有 url-s 应该是 "attached" 到上面提到的 url。
所以我需要这样的路由:
https://hostername.com/{some_parameter}/{controller}/{action}/{id}
一些示例:
- https://hostername.com/ApplicationName/Home/Profile
- https://hostername.com/ApplicationName/Home/Settings
- https://hostername.com/ApplicationName/FAQ etc...
在阅读了 Whosebug 上的一些 questions/solutions 之后,我对此的解决方案:
将默认路由更改为
routes.MapRoute(
name: "default",
template: $"{{parameter={settings.PrefixURL}}}/{{controller=Home}}/{{action=Index}}/{{id?}}");
其中 settings.PrefixURL => it's the some_parameter
并且它的价值是动态的。
我面临的问题=>
url 中的双参数,例如:
- https://hostername.com/ApplicationName/Home/Home/Profile
- https://hostername.com/ApplicationName/ApplicationName/FAQ
在本地测试时,默认路由的配置工作得很好,但发布后路由仍然有效,但 url 是错误的。
是什么导致了这个问题?
创建区域会解决到那种 url 的路由吗?
谢谢。
我的工作是编辑 web.config 文件上的路径并保持其余部分不变。
从 path="*"
到 path="/ApplicationName"
,其中 ApplicationName 是所需的路由参数。
我使用 ASP.NET Core 2.1 MVC 创建了一个 Web 应用程序。
目前我在发布应用程序时遇到路由问题。
url 应用程序发布的格式是这样的:https://hostername.com/{some_parameter}
我的应用程序生成的所有 url-s 应该是 "attached" 到上面提到的 url。
所以我需要这样的路由:
https://hostername.com/{some_parameter}/{controller}/{action}/{id}
一些示例:
- https://hostername.com/ApplicationName/Home/Profile
- https://hostername.com/ApplicationName/Home/Settings
- https://hostername.com/ApplicationName/FAQ etc...
在阅读了 Whosebug 上的一些 questions/solutions 之后,我对此的解决方案: 将默认路由更改为
routes.MapRoute(
name: "default",
template: $"{{parameter={settings.PrefixURL}}}/{{controller=Home}}/{{action=Index}}/{{id?}}");
其中 settings.PrefixURL => it's the some_parameter
并且它的价值是动态的。
我面临的问题=> url 中的双参数,例如:
- https://hostername.com/ApplicationName/Home/Home/Profile
- https://hostername.com/ApplicationName/ApplicationName/FAQ
在本地测试时,默认路由的配置工作得很好,但发布后路由仍然有效,但 url 是错误的。 是什么导致了这个问题? 创建区域会解决到那种 url 的路由吗?
谢谢。
我的工作是编辑 web.config 文件上的路径并保持其余部分不变。
从 path="*"
到 path="/ApplicationName"
,其中 ApplicationName 是所需的路由参数。