AlternateCssUrl breaks Site Templates

When trying to access Site Settings for a Site which is created on basis of a Site Template which has an Alternace CSS Url configured you will receive an unexpected error:

SharePoint Foundation    Runtime    tkau    Unexpected    System.Web.HttpException: Error executing child request for /Style Library/Style.css

This is caused because the Site Settings page doesn’t access the CSS at the Site Collection Root
(“http://servername/Style Library/Style.css”)
but instead searches for it in the layouts folder
(“http://servername/_layouts/1033/Style Library/Style.css”)

Pete wrote a PowerShell script to fix the problem afterwards:

$w = Get-SPWeb http://YourServer/YourWeb; 
$w.AlternateHeader = $null; 

But since this does not solve the actual problem, you always have to embed the reference to your StyleSheet in the MasterPage.

  name="<% $SPUrl:~sitecollection/Style Library/Style.css %>" 

But don’t forget, when you use SharePoint Foundation $SPUrl will not resolve, since this requires the Publishing Feature.

So in SharePoint Foundation you should reference your CSS like this:

<SharePoint:CSSRegistration name="/Style Library/Style.css" 
After="corev4.css" runat="server" /> 

Leave a Comment