Dynamic Banner Images

Topics: Customizing Orchard
Jan 17, 2015 at 2:27 AM
I've been trying for quite some time with little to no success in coming up with a method for creating banner images/background images in Orchard that change based on the user's (including anonymous/unathenticated users) session. I would like to have an image randomly selected and loaded as the site's banner image when the user first visits the site and remain the same image until they leave the site (session ends seems like the best option here) then when a new session is started a new image will be displayed. This way the banner isn't changing every time they request a new page on the site. I could do this using largely jQuery but it would be kind of messy and I would like to build it into Orchard using C# and make it into a standalone module to be distributed to other instances of Orchard, which is why I'm also trying to avoid modifying the global.asax or other such files.

My most recent attempt was to create a cookie that would store the name of the random image and then pull from that cookie which image to load on each page. Problem is I can't find a good way of creating this cookie when the user first visits the site. I was trying to use a route and controller action but this method overrode the pre-built routes with lower priority and didn't run at all on routes with a higher priority.

I think I know enough I could get this working if I just knew how to tie into the right events or methods for selecting a random image when the user first requests the site and then getting rid of that image (may not need to get rid of it but just generate a new random image on each initial application request) when the user leaves the site.

Any help would be greatly appreciated, thank you.
Jan 17, 2015 at 10:34 AM
Why not use a MVC Filter?
Jan 17, 2015 at 11:02 PM
I've thought of this option but don't really know what an MVC filter is or how they work in Orchard. Reading some posts it sounded like I might be able to make a filter and then register it in the global.asax file but don't want to alter that file. Is there maybe a tutorial you could point me to? Thank you.
Jan 18, 2015 at 11:56 AM
What Nick is proposing is exactly what I wrote about in your other thread: http://orchard.codeplex.com/discussions/577926. Filter is just a class you implement to hook to the action execution pipeline.