10/02/2010

Handle the 404 error in Sharepoint 2007

How to handle the 404 error in sharepoint 2007?
The Sharepoint include default page for 404 error, but we need to change it to our custom page.

So, follow the following steps:




1- Create a new page under your portal, such us: http://www.____.com/pages/FileNotFound.aspx

2- Go to the following path in your server:
\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1025
For arabic,
OR
\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033
For english.


3- Copy and past the sps404.html file

4- Rename the new file to any friendly name, such us: Mysps404.html

5- Open Mysps404.html file, and modify the following line:
STSNavigate("/_layouts/spsredirect.aspx?oldUrl=" + requestedUrl);

to:
STSNavigate(http://www.____.com/pages/FileNotFound.aspx);


6- Create a console application, to modify the default 404 error page to new page,
write the following lines:



System.Uri webApplicationUri = new Uri("http://www.____.com");

SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);

webApplication.FileNotFoundPage = "Mysps404.html";

webApplication.Update();





7- Run it in your server, and test the scenario.

2 comments:

  1. Thanks a lot
    It is really great and useful post

    Regarding the consol app. should we build it as dll and put it in GAC?

    Many thanks

    ReplyDelete
  2. Thanks, mdarwish. No, only copy the .exe file and run it in your server.

    ReplyDelete