Posts tagged WebForms
Cu3er .Net HttpModule Updates Your Configuration
0So I’ve been playing around with Cu3er, a great flash component for websites. It gives you the ability to create dynamic looking slideshows with great transition effects. I highly recommend you go over to Cu3er site and check it out. What I don’t like about Cu3er is that you can’t point it at a directory and let it pick up the image files dynamically. So I decided to help the .Net crowd with this little speed bump. I’ve done all the tedious work of mapping Xml to objects (trust me, I dislike doing this).
The main goal was to be able to drop images into a directory and update the configuration. I didn’t want to exclude anybody using Asp.Net, regardless whether you are using WebForms or ASP.NET MVC. So I finally ended up going with an HttpModule. The code executes every time a request is made and checks to see whether the contents of the image folder have been updated. For me it isn’t quite ideal, because I am reading the file system every time a request is made. I attempted to to use FileSystemWatcher but I couldn’t seem to get it firing in an ASP.NET environment.
So what are the advantages to using this HttpModule?
- Minimal editing of Xml. Just setup the main settings node in the config.xml file and it will be preserved.
- Could add great functionality to a CMS or dynamic site.
- Configurable from a configuration section
So What are the disadvantages
- Can only define one type of transition for all images.
- It is an HttpModule that fires every request (not ideal in my mind)
How do you make it work better for you?
- If you are using Asp.Net WebForms, create a HttpHandler that creates the configuration every time the config.xml is requested.
- If you are using Asp.Net MVC, create a controller action that returns a ContentResult containing the config.xml every time it is requested.
This is still an initial start to what I think can be a great helper to an already great flash component. Maybe V2 of Cu3er will have this functionality already built in, so this could be obsolete by then as well. But until then you are welcome to use this library and modify this library. I consider the code I wrote as an Alpha, if that. Realize that there could be bugs. Their is no warranty or guarantee expressed or implied (a little CYA).
To make this solution work you will need to do the following.
- Add a reference to the Cu3er .Net Library or Project to your web project.
- Add the configuration section to your web.config
- define the directory path to watch, and the location of the config.xml
- define the Cu3er module in the HttpModules section
- import the Html and Swf into the page you’d like to use Cu3er.
Check out the example I included with the Cu3er .Net project to see how to accomplish the steps above, and be sure to read the Cu3er documentation (the example is in ASP.NET MVC, but doesn’t really use the features of ASP.NET MVC to accomplish the goal).
