How is the default item controller registered/invoked in Orchard CMS?

蹲街弑〆低调 提交于 2019-12-13 19:42:58

问题


I'm trying to get my head around how multi-tenancy and routing works in Orchard CMS.

As I understand when Orchard starts a new shell (tenant) all the active modules for that tenant are loaded and any modules that implement IRouteProvider "publish" their routes. A ShellRoute is then added for each route which will only be matched for requests made to that tenant's hostname/suffix.

The request is then handled in the normal way by MVC (looking in RouteTable.Routes for a match).

What I can't figure out is how the default ItemController is invoked since I couldn't find a default route for this in the source. Also I notice when browsing to the home page, the id route parameter is populated with that of the home page content item so I'm assuming there is some kind of pre-processing going on before the controller is hit?


回答1:


There is a default IRouteProvider - Orchard.Mvc.Routes.StandardExtensionRouteProvider. It's responsible for registering default routes to controllers in form {module}/{controller}/{action}/{id}.

And yes, you're right - there is some preprocessing going on. A brief explanation:

  • Each item permalink (we call it an alias) is mapped to a route that points to an action responsible for displaying it. By default - Contents/Item/Display/{id}. Those mappings are kept in the database (AliasRecord and ActionRecord).
  • There is a special Route implementation - AliasRoute. This route is then registered once for each module and handles requests that match existing aliases. It all happens in Orchard.Alias module.
  • If the incoming request matches any alias, the call to AliasRoute.GetRouteData returns the underlying mapping. This way ASP.NET MVC framework knows which action to call.


来源:https://stackoverflow.com/questions/21516825/how-is-the-default-item-controller-registered-invoked-in-orchard-cms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!