How to create your own custom 404 error page and handle redirect in SharePoint

转载 2015年07月08日 00:22:20


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 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


*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: 

* 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.

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 M...
  • jiangxng
  • jiangxng
  • 2008年11月26日 18:42
  • 501

How to Build Your Own Blockchain 1 Creating, Storing, Syncing, Displaying, Mining, and Proving Work

I can actually look up how long I have by logging into my Coinbase account, looking at the history o...
  • omnispace
  • omnispace
  • 2018年01月29日 12:54
  • 136

Whitelabel Error Page(1)之 Not Found

Whitelabel Error Page 访问路劲 出错原因 代码块 代码功能 代码解释 实例如下 分析出错思路 解决方法 方法一添加代码 RequestMapping 方法二添加代码 Reques...
  • expect521
  • expect521
  • 2017年09月07日 16:47
  • 1328

How To Setup Your Own VPN With PPTP

How To Setup Your Own VPN With PPTP Published On: 20 Mar 04:28 Tweet  Vote on HN inShare Wri...
  • a454400828a
  • a454400828a
  • 2014年01月19日 20:55
  • 954

Make your own Neural NetWork之代码详解上

这篇博客接上一篇博客Make Your Own Neural Network简介。本文也是出自Make your own Neural NetWork这本书。上一篇博客讲了该书的行文结构,本文主要介绍...
  • hustqb
  • hustqb
  • 2017年09月01日 17:14
  • 802

Make Your Own Neural Network简介

极力推荐想学习神经网络的朋友一本书——Make Your Own Neural Network。这本书显示图文并茂的讲述了神经网络的工作原理,然后又一步一步的用Python搭建了一个简单的双层神经网络...
  • hustqb
  • hustqb
  • 2017年06月26日 17:22
  • 2053

How to make an altcoin

How to make an altcoin Leave a reply Okay, I’m going to preface this article by asking you two...
  • apace
  • apace
  • 2015年11月07日 11:56
  • 1089

404 Error Page

  我在开发jsp网站时,提交一个表单的数据给regDo.jsp处理,IE里器报错:404 Error PageSorry, you requested a page that does not ex...
  • my_dream_fly
  • my_dream_fly
  • 2007年02月01日 10:25
  • 569

How to redirect to a Custom Page for Event Receiver in SharePoint 2010

Introduction:An event receiver in SharePoint allows great flexibility to meet various user requireme...
  • lanhaizhixing
  • lanhaizhixing
  • 2011年03月01日 13:40
  • 1172

How to make your own VST host

Unlike the other software from Teragon Audio, MissWatson is not open source on account of an externa...
  • neo_yin
  • neo_yin
  • 2012年03月14日 17:55
  • 1010
您举报文章:How to create your own custom 404 error page and handle redirect in SharePoint