URL路由与数据库查询? [英] Url routing with database lookup?
问题描述
我想建立一个ASP.NET MVC站点,以便对特定的网址控制器存储在数据库中,而不是URL。
I want to build a ASP.NET MVC site so that the controller for a specific url is stored in the database instead of the URL.
这其中的原因是,我建立一个CMS系统和用户应该能够在不改变URL更改模板(控制器)。我也觉得控制器的名称是不相关的最终用户,我想干净网址:S。
The reason for that is that i'm building a CMS system and the users should be able to change the template (controller) without changing the URL. I also think that the name of the controller is not relevant for the end users and i want clean URL:s.
我意识到,我可以只添加在应用程序启动的所有路由,但对于像100万页的系统感觉就像是一个坏主意。
I realise that i could just add all routes at application start, but for a system with like 100 000 pages it feels like a bad idea.
是否可以存储URL:■在数据库中,并查找每个请求,然后映射请求到特定的控制器
Is it possible to store the url:s in the database and make a lookup for each request and then map that request to a specific controller?
推荐答案
基本上,你必须实现自己的IRouteHandler。
Basically you'll have to implement your own IRouteHandler.
答案和一些例如code的一部分,是在这个问题的答案选项3:
<一href=\"http://stackoverflow.com/questions/379558/mvcnet-routing\">http://stackoverflow.com/questions/379558/mvcnet-routing
Part of the answer and some example code is in Option 3 of this question's answer: http://stackoverflow.com/questions/379558/mvcnet-routing
更多信息:
<一href=\"http://weblogs.asp.net/fredriknormen/archive/2007/11/18/asp-net-mvc-framework-create-your-own-iroutehandler.aspx\" rel=\"nofollow\">http://weblogs.asp.net/fredriknormen/archive/2007/11/18/asp-net-mvc-framework-create-your-own-iroutehandler.aspx
这篇关于URL路由与数据库查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!