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