Monday, June 2, 2008

Multi-Tenant Architecture in SharePoint 2007

What is Multi-Tenant Architecture (MTA)?

MTA is similar to database views where same data is given different representations. As an example, consider a company portal. When an employee logs in, he will be interested more in company happening. On the other hand, when HR person logs in he will be keen to see new buddy referral or other relevant content. MTA implementation provides such dynamism with single portal.

MTA implementation options in SharePoint 2007:

Audience:

Audience is group of users for which the content can be target. SharePoint 2007 audience can consist of Active Directory users or other compatible domain users. We can target list, web part, and navigation for audience. Problem with Audience: Although provide customized content on the fly, Audience cannot be used with master pages.
So if the requirement is to provide different master pages depending on users it is not possible. In our example, if we want to provide a different look-and-feel for HR and employee then it would not be possible.

Solution:

Our problem can be reframed as switching master pages at run-time on the fly. SharePoint 2007 is built on top of ASP.NET 2.0 framework. Thus, we can harness the ASP.NETHTTP request pipeline and change the master page on the PreInit event of Page. For this, we need to create HTTP module and change the master page on the fly by reading page path from web.config.

Steps:

1. Define a class that implements IHttpModule

2. In the PreRequestHandlerExecute method provide a handler for page_PreInit

3. Set page.MasterPageFile property. This can be read from config. It could be similar to /_catalogs/masterpage/BlackBand.master

4. Add the Module to GAC

5. Add the entry to safe-controls section of web.config

6. Add entry to the httpModules section of web.config

That’s it. We are done with MTA implementation.

In my next post, I will provide a walkthrough of creating the MTA module with Visual Studio .NET 2005.

No comments: