Monday, September 22, 2008

Page Not found 404 Error Page Customization in MOSS Site

In some applications, the default 404 should be customized to another valid application page to show meaning information to the user. It's very simple to do with some steps.

The following steps should be followed to customize the 404 error message for MOSS.

1. In the MOSS server, should make a copy of
%system drive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\sps404.html and call it as 404Page.html
2. Should create a Virtual Directory /Errors in IIS under the MOSS root web application.
3. Should create a redirect aspx page, as /Errors/404redirect.aspx. This may be SharePoint Page or Normal ASP.Net Page. This page has the custom message to be shown to the user.
4. In 404Page.html , make the following change:
STSNavigate(“/Errors/404redirect..aspx?oldUrl=" + requestedUrl)
5. create a Console Application and insert the following code and run it in MOSS server. This code sets the new file not found page in sharepoint site.

System. Uri webApplicationUri = new Uri(http://ServerName/);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = " 404Page.html";

v Note:
By default this is set to null. FileNotFoundPage needs to point to an html file that lives in %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033. The file needs to be html only.

No comments: