How to get current site settings in IRouteProvider implementation?

Dec 11, 2010 at 2:16 PM

I'm struggling to retrieve current site settings in IRouteProvider implementation in my custom module. I injected IOrchardServices in the constructor, but WorkContext is null. It is possibly because none has been retrieved at the moment of creating routes, or maybe it is a bug? How can I work around this - maybe by some ContentManager.Query?

Dec 11, 2010 at 4:38 PM
Edited Dec 11, 2010 at 4:39 PM

I tried using ISiteService and IWorkContextAccessor with IHttpContextAccessor but neither worked:/ And no, the first one (ISiteService) worked, so I managed to get the settings in GetRoutes method (as seen in debug), but after enabling my module the whole site crashed with an ADOException (something with retrieving blog slugs). I'll post the whole error info later.


Dec 11, 2010 at 5:13 PM

My guess is that you won't be able to do that and should just declare your routes and put the switching logic in your controller action (by the way maybe a filter might be a good way to implement this, I don't know). Revert to the normal action when you have to. A little too tightly coupled to the present implementation sure but might get you going.

Dec 11, 2010 at 5:16 PM

I meant declare your routes from the route provider and do nothing else from there, then do the switching and reverting in the controller.

Dec 11, 2010 at 10:31 PM

Thanks, that worked. I created a workaround to redirect to the default controller from my controller actions if conditions (eg. setting and request Url) are met. Yes, it's a bit too tightly coupled to the implementation, but is ok atm. But in the future it may need some fixing (or at least some note in the docs when we are allowed to use certain objects and when not - a kind of lifecycle description).