AlternateHeader magic to style your SharePoint pages

Both in the portal and in team sites the underlying functionality is managed by an SPWeb. SPWeb functionality uses many generic ASPX pages defined in the folder LocalDrive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\1033. All pages in this directory look at the SPWeb property AlternateHeader. This property can be used to set the URL for an alternate .aspx page to use for rendering the top navigation area in SharePoint pages. Each ASPX page in this directory contains code to determine if the default header must be rendered or the specified header. it contains code like:

<%
string alternateHeader = SPControl.GetContextWeb(Context).AlternateHeader;
if (alternateHeader == null || alternateHeader == "")
{
%>
<TR><TD WIDTH="100%" COLSPAN="3"><!--Top bar-->
<TABLE class=ms-bannerframe cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=center noWrap><IMG id=onetidHeadbnnr0 alt=Logo src="/
layouts/images/logo.gif"></TD>
<TD class=ms-banner id=HBN100 vAlign=center noWrap width="99%"><!--webbot Bot="Navigation" startspan--><?XML:NAMESPACE PREFIX = SharePoint /><SharePoint:Navigation runat="server" LinkBarId="1002"></SharePoint:Navigation></TD>
<TD class=ms-banner>&nbsp;&nbsp;</TD>
<TD class=ms-banner style="PADDING-RIGHT: 7px" noWrap><SharePoint:PortalConnection runat="server"></SharePoint:PortalConnection></TD></TR></TBODY></TABLE></TD></TR>
<%
}
else
{
    Server.Execute(alternateHeader);
}
%>

Normaly this AlternateHeader is empty, but all SPWebs underlying the areas in the portal have this property set to PortalHeader.aspx, and all MySites have this property set to MySiteHeader.aspx. These files can be found in the folder Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\1033.

PortalHeader.aspx:

<%@ Page language="C#"     Inherits="Microsoft.SharePoint.Portal.SiteAdminPageNoBrowserCheck,Microsoft.SharePoint.Portal,Version=11.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<tr> <td colspan="3" width="100%">
 <SPSWC:PageRedirectControl runat="server" />
 <SPSWC:ExternalHtmlResourceElement runat="server" HtmlElement="StylesheetLink" FileContext="SharedStyle" FileName="ows.css" />
 <SPSWC:ExternalHtmlResourceElement runat="server" HtmlElement="StylesheetLink" FileContext="SharedStyle" FileName="menu.css" />
 <SPSWC:ExternalHtmlResourceElement runat="server" HtmlElement="StylesheetLink" FileContext="SharedStyle" FileName="sps.css" />
 <SPSWC:CustomCSSResourceElement runat="server"/>
 <SPSWC:PageHeader id="PageHeaderID" runat="server" PageContext="SitePage" ShowTitle="false" HelpID="NavBarHelpHome"/>
 <div class="ms-phnav1wrapper ms-navframe"> <SPSWC:CategoryNavigationWebPart runat="server" id="HorizontalNavBar" DisplayStyle="HorizontalOneLayer" /> </div>
</td> </tr>

MySiteHeader.aspx:

<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SPSWC:PersonalSpaceNavigationResponse runat="server" />
<tr><td colspan="3" width="100%">
 <SPSWC:PersonalSpaceNavigation runat="server" />
</td> </tr>

 

12 Comments

  • I have been trying to work with this today so this post is very timely. However, I have two questions:



    1. What setting controls this for pages in the layouts\1033 directory like listedit.aspx, etc. ? In other words, for admin pages, where can this alternateheader value be specified.



    2. When I try to add my own custom web parts to the portalheader.aspx page I get the famous &quot;safe control&quot; error. How can you add custom web parts (normally deployed to the bin dir) to this aspx?

  • Let me say it is not as cool as you're thinking because only aspx pages used by WSS AND SPS implement this alternateheader code. If you look at some portal specific page (speditcategory.aspx for example) you'll see that the header is designed in this aspx page itself.



    alternateHeader or even alternateCSS attribute of CAML definition for portal areas is not used in these specific pages. This is a big problem when trying to custom portals.

  • MJA, These pages are executed within the context of the web, if you look at the code you see how the alternate header is retrieved:



    string alternateHeader = SPControl.GetContextWeb(Context).AlternateHeader;



    So these pages use the AlternateHeader setting of the site they are executed in.



    About you second question: this is the security model of SharePoint, have a look at the MSDN site and looke at the SharePoint CAS article, or any article on building web sites. The assemblies used in your web part must be added as safecontrols to the web.config.

  • Eric, the portal specific pages use another mechanism using the tag: &lt;SPSWC:PageHeadTags id=&quot;PageHeader&quot; runat=&quot;server&quot; TitleLocId=&quot;SiteAdminMoveListing_PageTitle_Text&quot; OldExpires=&quot;0&quot; PageContext=&quot;SiteAdminPage&quot; PageType=&quot;Portal&quot; /&gt;. This tag renders the needed stylesheets. Changes in the portal should be done through stylesheet changes only, otherwise you really get into trouble. You have to modify all templates and pages, and some pages use server controls only and can't be properly modified.



    An approach I'm currently researching is to apply regular expression replacements on the HTML as ouputted by all ASPX pages using a httpmodule. Seems to be the only approach to get modifications to the actual code really working.



  • Hi Serge,



    great post, quite a bit of portal detail of which I was unaware. The only problem with the alternate header is that none of the web part pages or list pages use it, only admin pages under the _layouts directory.



    If I read your feedback right you're building a httpmodule to get around this?



    I've added a few pointers on my own blog with when having to restart iis with editing ONET.XML. Hopefully save a few others the pain..



    and it's my first post of useful information :-)

  • Good article!



    Only one question, for those aspx designing header by itself, how to customize their headers? any good approach?

  • For the main home page where we can find the onet.xml ? I tried renaming all onet also still postal is working same. And I made changes in portalheader.aspx, I did't noticed any changes in any pages. I tried even iisreset also.

    I believe I am missing something



    Other than this mothered I may have to change 100s of pages in frontpage



    Any help will be appreciated,



    Thanks



    Sunil

  • Hi Serge,

    This topic really interests me, can you explain a bit more about this.

    a) First where do I set the AlternateHeader to point to a new page? (I'm guessing ONET.xml)

    b)Will this effect existing areas and subsites or just new ones?

    c)If make some changes to portalHeader.aspx or mySiteHeader.aspx should these changes appear in existing or new sites/areas? (I've tried and they don't seem to)

    Thanks for your help,

    Nicky




  • <a href= Error. Page cannot be displayed. Please contact service provider for more details. >

Comments have been disabled for this content.