问题
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 (AliasRecordandActionRecord). - There is a special
Routeimplementation -AliasRoute. This route is then registered once for each module and handles requests that match existing aliases. It all happens inOrchard.Aliasmodule. - If the incoming request matches any alias, the call to
AliasRoute.GetRouteDatareturns 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