Saturday, September 8, 2012

Custom 404 Page Not found in SharePoint 2010

 

Well, now that we have successfully upgraded the MOSS 2007 sites to SharePoint 2010, there was a slight change in the URL structure in the new environment. In 2010, the site collection was moved to the top root level, more details on how to do this can be found here, as described below:

MOSS 2007: http://www.domianname.com/sitename/Pages/Home.aspx

SP 2010: http://www.domianname.com/Pages/Home.aspx

The issues that were identified:

#1. Bookmarked URLs might break for current users.

#2. The embedded deep-links in various email notifications already sent, may not work anymore.

#3. The various links to many pages, made available on other sites may start breaking with a page not found error.

The quick resolution that was agreed upon:

To implement a generic, custom page that should be displayed each time a user hits a 404 page not found error. This page would have a generic message and a link to take the user back to the home page.

How we did this:

Step 1: Create a meaningful 404CustomPage in the Site-Collection

a. Open-up the site and create a new Web-Part page in the Pages Library. Call it :”MyCustom404.aspx”.

b. Note the page URL; it should be “/Pages/MyCustom404.aspx”.

c. Design the page as per the business requirements by inserting Content Editors and Image web parts.

d. Place a generic but meaningful text on a content editor along with a link pointing back to, say, Home page.

Step 2: Create the Web Config Entries for the Web Application

a. Open-up the web-config file for the web application.

b. Create an entry for <httpErrors> section within the <system.webServer> as below:

<httpErrors errorMode="Custom" existingResponse="Auto">

<remove statusCode="404" subStatusCode="-1" />

<error statusCode="404" prefixLanguageFilePath="" path="/Pages/MyCustom404.aspx" responseMode="ExecuteURL" />

</httpErrors>

c. Save the config file and do an IISRESET.

Now go back and try to browse to a non-existing page on the site and you should see the custom 404 page being displayed.

Improvements that I can think of:

1. We can have a redirect logic on our custom 404 page to programmatically fix the url and redirect the user to the new page url.

2. We can also create a SP 2010 Solution package to automate the process of updating the web config file. This really helps in a multi-environment deployments by the admins.

I hope to get this improvements in-place in the next couple of weeks. I’ll update this post with the link to my new post so till then, have a nice time.

No comments: