18 February 2010

Domain Specific Master Page/CSS Loading...

Having different Branding for alternate user is one of the most demanding requirement from a business prospective. However I have been incisive with the HTTP handler to load my masterpages for various domain based users..
Here is the simplest solution suggested & implemented by my friends which is really effective and fast to incorporate..
All my efforts were utilized in created CSS (style Sheet) and its adjacent master file..
These .CSS & .master file are uploaded on the portal’s style library.
For effective implementation I have added the following entries in the master page it self.
CSS initialization has been done in the head tag while domain checking and loading on masterpage is carried on the body.

If you want you can perform the same by using a content Editor Webpart Also.
/*.MASTER File/*

/* HEAD SECTION Tags*/

<link href="../../Shared Resources/custom.css" rel ="stylesheet" type ="text/css"
/>
< link rel ="stylesheet" type ="text/css" title = "MasterStyle01" href =
"/Style
Library/MasterStyle01.css"
/>

< link rel ="stylesheet"type ="text/css" title = "MasterStyle02" href = "/Style Library/MasterStyle02.css" />

</HEAD>



Body must include the conditions to check the User Domain and to load its corresponding master file.

/*BODY SECTION Tags*/

<BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) !=
'undefined') _spBodyOnLoadWrapper();">
<WebPartPages: contenteditorwebpart id="ContentEditorWebPart1" runat="server"
__webpartid="{453BF7D0-85B6-40F5-AB3F-7255E09E41D5}">
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2>
<Content xmlns ="http://schemas.microsoft.com/WebPart/v2/ContentEditor"> <! [CDATA[<script>
var myLoginUser = '_LogonUser_'.toLowerCase();
if (myLoginUser.indexOf('Domain01') != "-1")
{
if(document.styleSheets)
{
for(var StyleSheetIterator = 0; StyleSheetIterator<document.styleSheets.length; StyleSheetIterator++)
{
if(document.styleSheets[StyleSheetIterator].title =="MasterStyle02")
{ document.styleSheets[StyleSheetIterator].disabled = false; }
if(document.styleSheets[StyleSheetIterator].title == "MasterStyle01") { document.styleSheets[StyleSheetIterator].disabled = true; }
</script>]]> </Content></WebPart> </WebPartPages:ContentEditorWebPart>
........


Note: check the tags existence in the master file itself before adding.
--
Special Thanks : Anshul Gagneja & Dhawal Mehta

No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: