In the SharePoint website, we have a built-in http404 page. That is to say, if the page you requested does not exist, the http404 page will be called.
What should we do if we want to set our own page? Such a simple operation is not easy in Sharepoint. If you can set this option in SharePoint central administration, it is the most natural thing. Unfortunately, the current version of SharePoint does not have this feature. We need to tell Sharepoint to use its own page. Now there are two methods.
First, write a console application and runProgramTo tell Sharepoint to use its own page,CodeSimilar to this:
Spweb site = This. Web;
System. Uri webapplicationuri = new uri (site. url );
Spwebapplication webapplication = spwebapplication. Lookup (webapplicationuri );
Webapplication. filenotfoundpage = mypageurl_404;
Webapplication. Update ();
This method needs to run an additional piece of code on the server. If you are not the server administrator, It is troublesome.
Second, you can make the above function into a feature. This feature can be set by adding a command in site action, so that the server administrator is not required, as long as it is the website set administrator. This approach aims to display a place in site collection administration that allows us to set the http404 page when we log on with an administrator account.
Thanks to Tim dobrinski.Article: Http://www.thesug.org/blogs/lsuslinky/Lists/Posts/Post.aspx? List = ee6ea231 % 2d5770% 2d4c2d % 2da99c % 2dc7c6e5fec1a7 & id = 5
Feature. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Feature
Id = "{guid }"
Title = "file not found page settings"
Description = ""
Scope = "Site"
Xmlns = "http://schemas.microsoft.com/sharepoint/">
<Elementmanifests>
<Elementmanifest location = "elements. xml"/>
</Elementmanifests>
</Feature>
Elements. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Elements xmlns = "http://schemas.microsoft.com/sharepoint/">
<Customaction
Id = "filenotfoundpage"
Groupid = "sitecollectionadmin"
Location = "Microsoft. Sharepoint. sitesettings"
Sequence = "2000"
Title = "file not found page"
Requiresiteadministrator = "true"
Description = "">
<Urlaction url = "~ Site/_ layouts/FP/set404page. aspx "/>
</Customaction>
</Elements>
We also need An ASPX file as the carrier of this command to set custom 404 pages.
<% @ Assembly name = "Microsoft. Sharepoint, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c" %>
<% @ Page Language = "C #" masterpagefile = "_ layouts/application. Master" inherits = "Microsoft. Sharepoint. webcontrols. layoutspagebase" %>
<% @ Import namespace = "Microsoft. SharePoint" %>
<% @ Import namespace = "Microsoft. Sharepoint. Administration" %>
<SCRIPT runat = "server">
Protected override void onload (eventargs e ){
If (page. ispostback)
{
Spweb site = This. Web;
System. Uri webapplicationuri = new uri (site. url );
Spwebapplication webapplication = spwebapplication. Lookup (webapplicationuri );
Webapplication. filenotfoundpage = pageurl_404.text;
Webapplication. Update ();
}
}
</SCRIPT>
...... (The HTML code of the page is omitted here)
Note that the custom 404 page must be placed in the/12/template/layouts/1033 directory (1033 is in English, if it is another language such as French, it is replaced with 1036, etc .)