SharePoint 2010 ‘Page not found (404)’ page the way it should be and this Inconvenient Catalog Item Page and ‘Page not found’ (404) experience from the master Waldek Mastykarz , and you're here, you're one step closer to the solution.
This blog post extends the Mastykartz strategy with just few lines of code.
Let's assume you developed those components:
- PageNotFoundHttpModule from SharePoint 2010 ‘Page not found (404)’ page the way it should be
- PageNotFoundWebPart from SharePoint 2010 ‘Page not found (404)’ page the way it should be
- Something like MaventionCatalogItemReuseWebPart from Inconvenient Catalog Item Page and ‘Page not found’ (404) experience
MaventionCatalogItemReuseWebPart simply redirects to site collection page not found url, but, since this is a server side redirection, the HTTP status code is 302 and the redirect location it's also well known, so i just modified PageNotFoundHttpModule in this way.
public class PageNotFoundHttpModule : IHttpModule { #region Const const string URL_RELATIVE_PAGENOTFOUND = "/Pages/PageNotFoundError.aspx"; #endregion #region Fields private HttpApplication webApplication; #endregion #region Public methods public void Init(HttpApplication context) { webApplication = context; webApplication.PreSendRequestContent += new EventHandler(webApplication_PreSendRequestContent); } public void Dispose() { } #endregion #region Event handlers void webApplication_PreSendRequestContent(object sender, EventArgs e) { HttpResponse response = webApplication.Response; HttpRequest request = webApplication.Request; if ((response.StatusCode == 404 && string.Compare(request.Url.AbsolutePath, URL_RELATIVE_PAGENOTFOUND, StringComparison.InvariantCultureIgnoreCase) != 0) || (response.StatusCode == 302 && string.Compare(response.RedirectLocation, URL_RELATIVE_PAGENOTFOUND, StringComparison.InvariantCultureIgnoreCase) == 0)) { webApplication.Server.TransferRequest(URL_RELATIVE_PAGENOTFOUND); } } #endregionSo what i added is essentially a new or condition.
0 commenti:
Post a Comment
Because of a lot of SPAM about courses, I need to moderate all comments here.
I ensure you that I will answer whenever possible (if you are not a spammer).