Multiple sites, one code base


Just recently, I have been tasked with solving the problem of going beyond co-branding without having to rewrite large portions of a site. We have a system in place, from a vendor, that allows us to switch out a logo and other graphics. Here is there solution:

<!– ASPX page –>
<img id="imgLogo" runat="server" />

//Code Behind
imgLogo.Src = "~/dealers/logos/default.gif";
if (Session["Dealer"] != null)
    imgLogo.Src = "~/dealers/logos/" + ((Dealer)Session["Dealer"]).Logo;

In order to reduce the load on publishing a site, the Dealers folder is a virtual folder. To add a new dealer, you simply drop a new logo in the folder and configure the dealer to use that logo.

The problem with this setup (excluding the code above, which is also an issue) is it only allows for co-branding by placing a logo on a page.

Problem 1: Going Beyond Co-Branding

Following our vendor’s example, I can refactor the database to store "resources" for the co-brand. This could then be used to pull pointers for CSS, etc. It is, of course, not very maintainable, so I would not opt for this direction.

There is a more elegant solution in the Microsoft .NET Framework. I can use themes to set up the basics. This allows me to create a new theme and apply it to my site. As long as I cover the same styles, I can make the site look however I desire. With skins, I can alter the look of individual controls.

If you have not worked with skins, you basically dupe the tag in question to the theme folder. You then alter the attributes you want to be different for this theme and give the skin and id. In your page, you then attach your controls to the skin. It works, but you end up kicking around the in the dark to do it, at least at times.

A better option, however, is to use simple HTML output and attach to a CSS stylesheet. But, there is a small issue here. Many of the complex ASP.NET controls output a lot of position code, including full tables (menu control). While you can use CSS styles attached to different attributes of the menu and alter them in the theme (without a skin), it is a bit tedious.

CSS Friendly Adapters

The menu problem can be solved with CSS Friendly adapters, which work rather nicely. I will cover my hacks to the CSS Friendly Adapter for the menu control a bit later, as the HTML output was rather "class" heavy for my tastes. If you can navigate from a single class or id, why subclass all of the child elements? That is a topic for another day.

NOTE: In the next few days, I will write about using (and hacking) the CSS Friendly adapters.

Problem 2: Getting the User to His Look

I have a couple of options here. I can use the URL the user is hitting and skin according to that URL. I can then keep the user in that look for his entire trip. I can also use personalization, but I feel this is overkill for the co-branding and customization needed. I am not planning on having multiple looks for a single co-brand, so there is no need to add a lot of metadata (asp.net personalization) to the database.

I can simple make a metadata table and link URLs to a particular theme. This is much lighter than personalization. I can also use the config file for this information, as long as I realize I will restart the application when I add additional "vendors". If I subclass the Page object and add some code to change the theme, I am pretty much golden. I can then track that user through a specific theme as he journeys on his way.

What if a vendor wants a separate database rather than have their data segregated via links to their entity record? I can also solve this either in config or in a metadata table.

BTW, I am rather fond of storing metadata in a persistent media other than configuration, especially in these situations. If it is oft used metadata, I will cache it on the application side to avoid the extra hits on the database, but I can easily configure a new set up in the database without having to completely redeploy an entire site.

Random Musings

After hacking the CSS Friendly adapters, I have a menu that works without much more than a nested set of unordered lists. I am now investigating connecting the proper JavaScript file(s) to the theme, but that should be solved shortly. I have the new Page class using a factory method, which is configurable, so I can alter that library after I am sure about where the persisted data will lie (database is my primary leaning right now).

In the next week or so, I have a few blog topics to hit:

  1. Understanding Lamda Expressions – I felt a tutorial on getting one’s head around Lambda expressions would be nice
  2. Hacking the CSS Friendly Adapters – Basically hacking so it can easily use a drop down menu with sliding doors (method of using sizeable images for a menu "tab").
  3. Separation of Concerns – wanted to hit this again, as the idea is not sinking in for some people 🙂
  4. MVC Framework – not sure what, but I have some ideas

Peace and Grace,
Greg

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: