Multi Presentation enterprise solution
I am working on designing an enterprise web application which will have single codebase and single database (don't need any flexibility in database based on tenants) but different presentations based on clients. We might have 3 to 4 different clients (websites) utilizing same core logic and skeleton but client specific headers, footers, images, css etc. I need a multi-presentation solution then a full fledge multi-tenancy. Most of the samples I saw online are geared towards full fledged multi-tenancy I don't think I need that complicated stuff. I found some information here which is very useful in my case:
http://jasonjano.wordpress.com/2010/02/22/multi-presentation-websites-for-c/
As suggested in above link, I am able to identify and grab a unique ID based on the domain requested as per below configuration in my web.config file:
<configuration>
<appSettings>
<add key="MySite1.MyDomain.com" value="1"/>
开发者_如何学运维 <add key="www.MySite1.MyDomain.com" value="1"/>
<add key="MySite2.MyDomain.com" value="2"/>
<add key="localhost" value="1"/>
</appSettings>
</configuration>
After this, how do I dynamically select my Master page, images and css files based on the ID? Also I will be populating "CustomAppSettings" class (as suggested in article) from database, Is it advisable to make it static to it can be accessed in different layers? otherwise what is the recommended way?
Your suggestions would be very much appreciated.
This might help you with detecting the 'tenant' from the incoming request.
I would not dynamically select a different MasterPage file but rather render different content out to the MasterPage via Html Helpers / Patrial Views (or both).
Glad to see you are getting some use out of that article. Regarding the answer, I usually use a custom page class that inherits from system.web.ui.page. In the page_init of the custom page class you can set the master page, etc..
Something like (psuedo code)
class MyCustomPage : System.Web.UI.Page
{
public void Page_Init(object sender, eventargs e) {
this.MasterPageFile = CurrentSettings.MasterPageFile <Or however you are getting your masterpage file>
}
Then, in your pages, inherit from the MyCustomPage class instead of System.Web.UI.Page.
Good Luck
精彩评论