tags:

views:

350

answers:

1

Ive got an application that different domains are connected to, instead of copying and modifying each application i use same physical location on hard drive but separate application pools and websites on IIS.

Basically i want to change a theme based on hostname. ie. user comes to "websome.com" gets "websome" theme and user comes to "jamessome.com" gets "jamessome" theme.

I set the theme in web.config "pages" attribute which applies the theme globally to whole website. Is there any way i can modify that setting on fly based on domain use entered from? It is probably possible but what are downsizes and what do you suggest to do with little code in order to simplify solution. As i understand if i edit web.config each time user comes in it will take lots of time which is not that elegant... So any ASP.NET gurus out there can write two lines of code so magic will happen ?

There are few solutions for these problem on the website but this will require me to add code to Page_Init event of every page on the site which is unrealistic.

+4  A: 
Abel
Interesting approach.
Filip Ekberg
thanks, mate... will try to apply it
eugeneK
That's awesome, thank you very much! :)
Filip Ekberg
Abel, i'm using code on page and it does not generate class for each page like code behind method does. Can i just wrap all inside of script runat=server with partial class with inhiritance ?
eugeneK
This would be a great time to start using code-behind and separate the layout / content from the business logic. You can set the `Inherits` attribute of `@ Page` on top of your file to the class you created in the App_Code folder (assuming you created a ThemedPage there).
Abel
Side note: a partial class is a different concept then inheritance and through the notion of partial classes you cannot force inheritance, you'll have to write an extra partial class for each page (which is why using the `Inheritance` attribute is easier).
Abel
"Partial" means "Protected" on god's language ?
eugeneK
Thanks Abel... Anyway, i did a test with wrapping try/catch and deleted the theme, somehow i still got an exception System.Web.HttpException of that kind...
eugeneK
_"Partial" means "Protected" on god's language ? _ >> me not understand, but no, that it doesn't mean. Partial means: have as many class declarations by the same name as you wish and they are combined.
Abel
For helping you with the exception I need to see your code, the place the exception occurs, the stacktrace. Make a small page that illustrates the problem and post it as a new thread. I tested my solution and it works "out of the box" but I don't know how involved your situation is.
Abel