This project is read-only.

Intercept Root Url?

Topics: Customizing Orchard, Writing modules
Mar 25, 2015 at 4:51 PM
I'm creating a module for Orchard where I'm creating multiple dashboards for the user. The user can select the dashboard that they would like to show by default. This dashboard should act as the homepage, but only for the individual user.

I would like to "intercept" when the root URL of the site is called, and then re-route the call to the users default dashboard.

I've attempted to create a new route in my modules route class, but I'm either getting the syntax wrong, or I'm not fully understanding how the root URL is handled in Orchard (or MVC). I can define and hit normal routes with no problem, and I was able to create a wild card route that is hit on every request, but I can't seem to figure out how to configure a route for the root URL.

Is it possible I'm taking the wrong approach? Should I be using an action filter instead?
Thanks for your help. Any guidance will be greatly appreciated.
Mar 25, 2015 at 5:24 PM
No need to override routes etc. You should implement an action filter that will issue a correct redirect when request to root URL comes, just that.
By action filter I mean a class that implements both FilterProvider and IActionFilter. Put your logic inside the OnActionExecuting method and set filterContext.Result to a correct RedirectResult when necessary.
Mar 25, 2015 at 8:01 PM
Edited Mar 25, 2015 at 8:02 PM

Thanks for the quick reply.
Can you suggest where I can find more information on the page / event lifecycle in Orchard?

I think the Action Filter sounds like a great approach, but I'm concerned about interfering with other OOTB functionality, such as user registration and default login behavior. I'd hate to implement an Action Filter that solves my dashboard needs, but in turn creates issue with other parts of the site.
Mar 25, 2015 at 11:01 PM
Page (or better - request) lifecycle in Orchard is exactly the same as in ASP.NET MVC - there is absolutely no difference here.

Action filters are ASP.NET MVC core functionality, not something "Orchardy". The only thing is you need to also implement FilterProvider to tell Orchard to register this particular filter in request pipeline. In regular apps it's done manually.

You shouldn't worry about interfering with other functionality as long as you just need to redirect a user from the root URL. It would just redirect a user to another page automatically, keeping everything intact.
Mar 25, 2015 at 11:42 PM
Thanks again pszmyd. I'm just about to wrap this up. Your help is very much appreciated.