Blog

How to Customize your “ERROR 404” page in SharePoint.

By Edith C.
 
This is very useful when for instance, Google has one of your site’s no longer existing pages, on cache: or if a user types a wrong URL directly on the browser.
 
Here you’ll find the steps needed for customize your Error 404 Page, with SharePoint.
 
1. First you have to create a new page in your SharePoint Page library, personalize it with your site’s style, you add an error or page not found message. In my case I created the page: Error.aspx
 
Error.aspx
 
2. Now in the server where the SharePoint site is located, on the Layouts folder (systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\) you have to create an ASPX page to redirect it to the personalized Error page.  I created the “redirect404.aspx”. This page must have the redirect code to your SharePoint Page. I used a simple  javascript:

<script type="text/javascript">location.href="/Pages/Error.aspx";</script>
 
3. I the same Layouts’ address, there’s a folder named \1033, in this folder you’ll find the sps404.html file, you have to copy this file, and store it with a representative name like “mysite404.html”. This file contains a STSNavigate redirection script, we need to change the default parameter (”/_layouts/spsredirect.aspx?oldUrl=” + requestedUrl) to the “redirect404.aspx” address, this is:

STSNavigate("/_layouts/redireccionar404.aspx");
 
4. Until now, we’ve just done de redirection (in two steps) to our Error.aspx page , now we have to let SharePoint know that the “FileNotFound” is “mysite404.html” instead of  sps404.html; to do this we just have to create a little console application to assign the FileNotFoundPage to our Web Application.
 
5. The console program would be something like this:

string uriString = "";
Console.WriteLine("Uri String: ");
uriString = Console.ReadLine();
System.Uri webApplicationUri = new Uri(uriString);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
string fnfPage = "";
Console.WriteLine("File Not Found Page name: ");
fnfPage = Console.ReadLine();
webApplication.FileNotFoundPage = fnfPage;
webApplication.Update();

 
6. We just have to run the application in the server where the site is located, and provide the right parameters.
 
Run application
 
7. And that’s it , the  next time people looks for a non existing page in your Site, SharePoint will redirect them to Error.aspx
 
 
 

Comments

Leave a comment

 
 
 
 
CAPTCHA Image Validation