繁体   English   中英

ASP.NET Core MVC使用参数路由到url

[英]ASP.NET Core MVC route to url with parameters

我使用ASP.NET Core 2.1 MVC创建了一个Web应用程序。 目前我在发布应用程序时遇到路由问题。 将发布应用程序的url格式为: https://hostername.com/{some_parameter}https://hostername.com/{some_parameter}

我的应用程序生成的所有url-s应该“附加”到上面提到的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... 

在stackoverflow上阅读了几个问题/解决方案之后我的解决方案:将默认路由更改为

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

在本地测试时,默认路由的配置工作正常,但在发布路由后仍然有效,但是网址错误。 可能导致问题的原因是什么? 创建区域会解决到这种网址的路由吗?

谢谢。

对我来说,工作是在web.config文件上编辑路径,并保持其余的灵魂不变。 path="*"path="/ApplicationName" ,其中ApplicationName是所需的路由参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM