本文介绍了MVC中的自定义路由URL(appurl / {uniqueId} / {controller} / {action} / {id})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们正在尝试在c#中构建一个mvc应用程序。我们希望更改路由配置,使其在域url和控制器名称之间具有uniqueId。uniqueId是动态的,并且基于uniqueId,应用程序将通过弹性数据库服务器连接到各自的
数据库。 / p>


问题是mvc正在考虑使用uniqueId作为控制器。当我搜索时,我找到了一些解决方案,其中uniqueId是静态的并且已经定义。请找到错误图片的链接:  https://ibb.co/y89KVN8



I正在寻找像Azure devops应用程序网址的解决方案。如果你看看Azure devops,它的多租户应用程序服务于几个客户。  例如:dev.azure.com/{clientname}  -
客户端名称可以是任何内容,它将作为弹性数据库池的tenantid。我尝试实现此解决方案,但MVC框架不支持此类模式,并将{clientname}视为控制器名称。 



例如: 
想要构建如下所示的内容并且它不起作用



URL
portal.example.com/{uniqueId}/Account/login



RouteConfig
routes.MapRoute(name:" Default",url:" {uniqueId} / {controller} / {action} / {id}",默认值:new {controller =" Account",action =" Login",id = UrlParameter.Optional,
uniqueId =
UrlParameter .Optional});



请帮我们解决这个问题。有没有其他办法让这个工作。提前致谢

解决方案

We are trying to build an mvc application in c#. We want to change the routing config in such a way that it has uniqueId in between domain url and controller name.The uniqueId is dynamic and based on uniqueId the application will be connecting to there respective database through elastic database server.

The problem is that mvc is considering uniqueId as a controller. When i searched i found few solutions where uniqueId is static and is already defined. Please find the link for error image: https://ibb.co/y89KVN8

I was looking for solution like Azure devops application url. if you look at Azure devops, its multi-tenancy application serving several customers. for example: dev.azure.com/{clientname} - the client name can be anything and that will act as tenantid for elastic database pool. i tried implementing this solution, but MVC framework is not supporting such pattern and its considering {clientname} as controller name. 

For Example: I want to build something like shown below and it is not working

URL: portal.example.com/{uniqueId}/Account/login

RouteConfig: routes.MapRoute( name: "Default", url: "{uniqueId}/{controller}/{action}/{id}", defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional,uniqueId= UrlParameter.Optional } );

Please help us with this approach. Is there any other way to get this working. Thanks in advance

解决方案


这篇关于MVC中的自定义路由URL(appurl / {uniqueId} / {controller} / {action} / {id})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 23:47