1

I am using httpmodule to show custom 404 message. This works fine, if the callstack is set to true in web.config. But in the actual environment, callstack needs to be set to false. When the call stack is false, the page not found is not working.

This is the code used. I have followed this link: http://blog.mastykarz.nl/sharepoint-2010-page-not-found-404/

[CODE]

public class PageNotFoundHttpModule : IHttpModule { private HttpApplication app; private string pageNotFoundUrl = "/_layouts/MyApp/404.aspx";

    public void Dispose()
    {
    }

    public void Init(HttpApplication context)
    {          
        app = context;
        app.PreSendRequestContent += new EventHandler(app_PreSendRequestContent);          
    }

    void app_PreSendRequestContent(object sender, EventArgs e)
    {          
        HttpResponse res = app.Response;
        HttpRequest req = app.Request;

        if (res.StatusCode == 404 &&
            !req.Url.AbsolutePath.Equals(pageNotFoundUrl, StringComparison.InvariantCultureIgnoreCase))           
        {
            app.Server.TransferRequest(pageNotFoundUrl);
        }
    }     
}

[/CODE]

In the web.config I have:

CallStack="false" AllowPageLevelTrace="false"

customErrors mode="On" redirectMode="ResponseRedirect" defaultRedirect="~/_layouts/MyApp/CustomErrorPage.aspx">

under Modules

<add name="PageNotFoundHttpModule" type="MyApp.HttpModule.PageNotFoundHttpModule, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=keytoken" preCondition="integratedMode" />

If I set the callstack to true, i am getting the 404 page.

How to fix this?

Thank you

1

1 Answer 1

0

Modules (and handlers) running on IIS 7 (which is the prereq for SP2010) must be declared in the section.

Move the code

<add name="PageNotFoundHttpModule" type="MyApp.HttpModule.PageNotFoundHttpModule, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=keytoken" preCondition="integratedMode" />

under <system.webServer> section

1
  • Thank you very much for the reply. I have added that under "system.webserver" . In this there is a section called modules. Inside that i have added the pagenotfoundmodule. This is how I have earlier. But it is not working. If the callstack is set to true, it is working. If the callstack is set to false, it is not working.. Any help on this.. How to fix this?
    – venkatzeus
    Sep 22, 2011 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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