How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?

People alway ask how to use their own 404 file not found error page vs. the generic one from IE in MOSS environment. The following example catches the 404 error and sends users to a redirect page.

 

Here's the steps:

 

1. In your MOSS server, make a copy of

%systemdrive%/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/TEMPLATE/LAYOUTS/1033/sps404.html

and call it my404.html

 

2. Create a Virtual Directory in IIS under your MOSS root web application. For example /errors

3. Create your own redirect aspx page, for example /errors/my404redirect.aspx and code your redirect logic in there. This is a normal asp.net page. 

4. In my404.html, make the following change:

            STSNavigate("/errors/my404redirect.aspx?oldUrl=" + requestedUrl);

5. Create a Console Application and insert the following code and run it in MOSS server

 

           System.Uri webApplicationUri = new Uri(http://MyMOSSServer/);

           SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);

           webApplication.FileNotFoundPage = "my404.html";  //*note

           webApplication.Update();

*Note: By default this is set to null. FileNotFoundPage needs to point to a 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.

 

6. Now when you browse to a page that doesn't exist, you should expect to be brought to the redirected page.

 

 *Another note:

In IE there's a "Show friendly HTTP error messages" setting which is ON by default in Internet Options->Advanced. With this setting on, sometimes your custom error page is not displayed. In order to override this setting, both my404.html and /errors/my404redirect.aspx from the above steps need to be larger than 512 bytes in size. Refer to the following KB about this setting: http://support.microsoft.com/kb/218155 

* This seems to be working within a site collection context only, i.e. http://MyMOSSServer/sites/siteA if sites is a wildcard inclusion managed path and siteA doesn't exist in MOSS then this URL will NOT trigger the custom 404 error page set to SPWebApplication.FileNotFoundPage property.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值