Wednesday, March 16, 2011

Having seperate themes - if the same host address has www. and a version with no www.

I have a set of themes for my website, which are to be used with different requests from different urls. So if the url = www.xyz.com I load a different theme, as opposed to www.abc.com.

However, I have tried having a theme called www.abc.com and a theme called abc.com, and in my webform codebehind I have a preinit page event which says if url.contains(abc.com), then load theme abc.com, if url.contains(www.abc.com), then load theme www.abc.com (valid theme).

Starting from the beginning again, what is the best way to have and call a theme depending on whether the url has www. or not, but the same host. So how can I have seperate themes for abc.com and www.abc.com, and then load the latter when the url is www.abc.com and the former when the url, is obviously, abc.com?

Thanks

From stackoverflow
  • Not exactly sure what you're after here, but if you are testing the url in that order, and using an else, then it looks like the first case will always be true, so test for the more specific case (www) first.

    Would also suggest that you look at testing for url.StartsWith, and include the protocol variations that you might expect, as you never know if those strings might show up somewhere else in the url in a year or two, and your theme switcher might stop working.

    You could then just swap around master pages to change your theme, or if you are using the App_Theme thing, do some switching on that. Always found the aspnet theme thing to be a little bit clunky myself.

0 comments:

Post a Comment