Wednesday, October 17, 2012

Set the Custom 404 Error Page


Hi,
Have you ever tried setting up the Custom Error Page in SharePoint 2010. For long time I was aware of only below such ways of setting up the Custom Error Page.
1.) Modify the web.cofig file and set the <customErrors> = "ON".
2.) Either you can set it from IIS.
3.) Programmatically set the custom 404 page.
But a another way is a much smarter way i.e. To configure SharePoint Foundation server or SharePoint Server 2010 to point to a custom 404 error Web page via File System.
  1. Log on to the computer that is running SharePoint Server 2010 by using an account that has administrative permissions.
  2. In Windows Explorer, locate the following folder:
    c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID
  3. Create the custom HTML file:
    1. On the computer that is running SharePoint Server 2010, copy the Sps404.html file to a temporary folder.
    2. Rename the Sps404.html file. For example, give the file the following name:
      Custom404.html
    3. Modify the Custom404.html file to suit your needs for a custom 404 error message using an HTML editor.
    Note : In sps404.html you will notice STSNavigate("/_layouts/spsredirect.aspx?oldUrl=" + requestedUrl). You need to modify the line as per you requirement , either create another .aspx page and save it in _layouts folder or can directly point to any .aspx file located on the sharepoint library. i.e. STSNavigate("http://www.mytestsite.com/about/pages/404notfound.aspx");
    4. Copy the Custom404.html file to the %systemdrive% \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID folder.
    Run the following PowerShell commands from the SharePoint 2010 Management Shell:
    $webapp =Get-SPWebApplication http://<serverUrl>:<port>
    $webapp.FileNotFoundPage = "Custom404.html"
    $webapp.update()

No comments:

Post a Comment