关闭

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

254人阅读 评论(0) 收藏 举报
分类:

 

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10138次
    • 积分:196
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:19篇
    • 译文:1篇
    • 评论:2条
    文章分类