SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have custom IHttpModule to redirect users to my 404 aspx page.

This example was found somewhere in the internet and this part looks like working well but today administrators reports next problem:

Hi   Has been seen on this today and have found out. It turns out that it's http module "PageNotFound" that troble it for WebDAV when saving from Office documents. It adds an http 302 redirect when to store documents. This happens only if the document does not exist, works fine if you save over an existing document. Can be tested to remove / add "PageNotFoundHttpModule" from web.config WebDAV works fine.

 void ApplicationPreSendRequestContent(object sender, EventArgs e)
            HttpResponse response = app.Response;
            string requestedUrl = app.Request.Url.AbsolutePath;

            if (string.IsNullOrEmpty(requestedUrl))
                LoggingService.WriteError("PageNotFoundHttpModule. PreSend request: HttpApplication Request.Url.AbsolutePath is null ");

                var urlElements = requestedUrl.Split('/');
                if (urlElements.Length > 0)
                    int pageElementIndex = urlElements.Length - 1;
                    string pageName = urlElements[pageElementIndex] as string;

                    if (string.IsNullOrEmpty(pageName))
                        pageName = string.Empty;

                    if (response.StatusCode == 404 && response.ContentType.Equals("text/html", StringComparison.CurrentCulture))
                        var pathLowercase = Constants.PageNotFoundUrl.ToLower().Trim();
                        var message = string.Format("{0}?oldUrl={1}&k={2}", pathLowercase, requestedUrl, pageName);
                        if (!pathLowercase.EndsWith(pageName.ToLower().Trim()))
            catch (Exception ex)
                LoggingService.WriteError(ex, "PageNotFoundHttpModule. Exception while working");

I checked logs and i see next exception:

    PageNotFoundHttpModule. Exception while working  Thread was being aborted.  
   at System.Threading.Thread.AbortInternal()     
at System.Threading.Thread.Abort(Object stateInfo)     
at System.Web.HttpResponse.End()     
at PageNotFoundHttpModule.ApplicationPreSendRequestContent(Object sender, EventArgs e).

But I really dont know what is gooing wrong with this thread and why its Aborted. Any ideas?

share|improve this question

This is the natural behaviour of HttpContext

When you try to redirect the page, the current thread will be aborted and the system will throw an exception.

If you don't want the thread to abort, pass false to redirect method.

response.Redirect(message, false);

share|improve this answer
up vote 0 down vote accepted

We should check that HTTPmethod is not profined. And only then use redirect.

app.Request.HttpMethod != "PROPFIND"

share|improve this answer

Your Answer


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.