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

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

share|improve this question
    
did it help in anyway? –  Falak Mahmood Sep 22 '11 at 7:10
add comment

1 Answer

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

share|improve this answer
    
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 '11 at 7:16
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.