Click here to Skip to main content
Licence CPOL
First Posted 7 Jan 2008
Views 15,151
Bookmarked 12 times

How To Remove noisy ASP.Net Error page

By | 7 Jan 2008 | Article
Remove noisy ASP.Net Error page

Introduction

When I start web development in general first thing all programmers and communities say that you shouldn’t every show detailed errors for end user clients but ASP.NET error page it more than detailed where some time show source code content or tables names in case programmer don’t use n-tier style, so after good study in ASP.NEt I figure good way to hide errors from hacker, or any bad Guy ;-) which goes in next steps below:

Steps

1- Add special web.config tags

2- Build error handler class.

3- Create Custom error page

4- Log error on system event log.

In Action

Step one

In web.config file add following tag in system.web section:

<customErrors mode=”On” defaultRedirect=”~/CustomError.aspx” />

Step Two

Create error handler class:

public class M3MErrorHandler : IHttpModule

{

public void Init(HttpApplication app)

{

app.Error += new EventHandler(app_Error);

}

protcted void app_Error(object sender, EventArgs e)

{

HttpApplication app = (HttpApplication)app;

HttpContext context = app.Context;

Exception error = context.Serve.GetLastError().GetBaseException();

context.Response.Clear();

CompilationSection compilationConfig = (CompilationSection)WebConfigurationManager.GetWebApplicationSection(“system.web/compilation”);

if (compilationConfig.Debug) context.Server.Transfer(“~/Debug.aspx”);

else

context.Server.Transfer(“~/Error.aspx”);

}

public void Dispose()

{ }

}

}

}

Step Three

Create Two pages each one for debug information display other for public use that show error note.

Step Four

In Gloabls.asax

Record error into event log using system log in side Application_Error event

as follow

Exception x = Server.GetLastError().GetBaseException();
EventLog.WriteEntry(LOG_SOURCE, x.ToString(), EventLogEntryType.Error);

Thats all :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mohm'ed Melhem

Software Developer (Senior)

Palestinian Territory (Occupied) Palestinian Territory (Occupied)

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 8 Jan 2008
Article Copyright 2008 by Mohm'ed Melhem
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid