I was reading this MS KB article 'How to point to a custom 404 error page in Windows SharePoint Services 3.0 or in MOSS'. I thought I'd throw together a simple administrative page to pull it all together. I've packaged this up in this solution file.
Once you active the 'Manage Custom 404 Page' feature, you will get a new menu item in the Application Management page in Central Admin:
From here you get a simple page that you can type the 404 page name for the selected web application:
The code is super simple:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.SharePoint.Administration;
using System.Web.UI.WebControls;
namespace SP404Handler
{
public class SP404HandlerPage : LayoutsPageBase
{
protected WebApplicationSelector lstWebApps;
protected PageLevelError pageLevelError;
protected Button ButtonDoneOK;
protected TextBox txt404PageName;
protected Microsoft.SharePoint.WebControls.InputFormSection I404Section;
protected void lstWebApps_OnContextChange(object sender, EventArgs e)
{
try
{
SPWebApplication webApp = lstWebApps.CurrentItem;
BindData(webApp);
}
catch (Exception err)
{
pageLevelError.ErrorText = err.Message;
}
}
protected void DoneButtonOkClick(object sender, EventArgs e)
{
SPWebApplication webApp = lstWebApps.CurrentItem;
try
{
webApp.FileNotFoundPage = txt404PageName.Text;
webApp.Update();
}
catch (Exception ex)
{
pageLevelError.ErrorText = ex.Message;
}
}
private void BindData(SPWebApplication webApp)
{
txt404PageName.Text = webApp.FileNotFoundPage;
}
}
}
The source can be downloaded from here, or a complied solution from here.