Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We build an HTTP Module to handle 404 errors on a public SharePoint 2010 project.

We found the new functionality in SharePoint 2010 that sets the FileNotFound property of the Web Application very lacking, so instead we implemented the technique described by Waldek: Better SharePoint 2010 ‘Page not found (404)’ page with the Mavention Page Not Found Widget

Here's the implementation of the HTTP Module:

private string pageNotFoundUrl = "/Pages/page-not-found.aspx";

void HttpApplication_PreSendRequestContent(object sender, EventArgs e)
{
    HttpResponse httpResponse = httpApplication.Response;
    HttpRequest httpRequest = httpApplication.Request;

    if (httpResponse.StatusCode == 404
        && !httpRequest.Url.AbsolutePath.Equals(pageNotFoundUrl, StringComparison.InvariantCultureIgnoreCase))
    {
        Logger.Warn(String.Format("PageNotFound HttpModule: content at {0} not found.", httpRequest.Url.AbsolutePath));

        if ((!String.IsNullOrEmpty(httpResponse.ContentType))
            && (httpResponse.ContentType.Equals("text/html", StringComparison.InvariantCultureIgnoreCase)))
        {
            httpApplication.Server.TransferRequest(pageNotFoundUrl);
        }
    }
}

This works like a charm, except on the Manage Content & Structure section of the site. Obviously, anonymous users won't have access to this, and I can simply remove the HTTP Module from the authoring site where users are signed in, but now I'm curious why I'm seeing the following behavior:

When clicking around the Manage Content & Structure page, I occasionally get an authentication popup. I can cancel the popup and the page would still work OK. After some troubleshooting, I figured out that it was being caused by the PagNotFound HTTP Module.

Here's what I see in Fiddler every time this happens:

Fiddler Trace

So it appears that the page is referencing an image that doesn't exist, browsing to this URL (http://localhost/_layouts/1033/styles/siteTitleBKGD.gif) directly causes the same behavior.

I confirmed that when I turn off the HTTP Module, I get a straight 404 when browsing to this URL. I can also replicate this by making up any invalid URL within http://localhost/_layouts/1033/styles - it doesn't have to be an image.

Any thoughts on this behavior? I'm this close to adding a //HACK to the code to bypass the module for URLs within http://localhost/_layouts/1033/styles.

There's nothing at _layouts/none - I have no idea what that is and why Manage Content & Structure requests it. Browsing to that directly will correctly invoke the PageNotFound HTTP Module.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I have encountered the exact same issue you're having - a HTTP Module that handles 404, and getting 404's (and thus an infinite loop or a 500) when going to Manage Content and Structure.

We also did what you did, and just remove the module for the authoring environment, but another 'short term' workaround until Microsoft sort this, is to put a 1x PNG file with the same filename in the same path that is reporting the error, just to stop it 404'ing.

EDIT: I don't remember /_layouts/none, you might as well just need a //HACK for that. I do believe this is a legitimate bug with SharePoint.

share|improve this answer
    
These 404 URLs are also called when loading the AssetPortalBrowser and UploadEx dialogs causing similar Access Denied errors and authentication popups. –  robwilliams Jul 17 '13 at 23:03
add comment

I have solved this problem by checking referrer URL. If not null, it should be equal to request URL. Otherwise it is a resource in the page, I assume. Works like a charm!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.