Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3215248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:09:20+00:00 2026-05-17T15:09:20+00:00

Currently, we are doing error handling via Application_Error in global.asax.vb : Sub Application_Error(ByVal sender

  • 0

Currently, we are doing error handling via Application_Error in global.asax.vb:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    OurLibrary.HandleError(Me)
End Sub

HandleError then logs the error into a database, displays an informative message to the user and returns the correct status code (404 or 500) depending on the type of exception that occurred:

Public Shared Sub HandleError(httpApp As HttpApplication)
    ''# do some logging
    ...

    ''# show some details about the error and information about how to contact us
    httpApp.Response.Write(...)

    httpApp.Response.StatusCode = 404 or 500
    httpApp.Server.ClearError()
End Sub

Server.ClearError is necessary, because otherwise the default ASP.NET error handling kicks in and the user is shown — depending on the current state of <customErrors> — either the “yellow screen of death” or an information message about how <customErrors> can be turned off.

The drawback of using ClearError is that I can no longer use <customErrors> to override the error handling behaviour — something which brought quite a bit of trouble during the recent ASP.NET vulnerability, where the recommended workaround was done using <customErrors>.

I know that I could use only customErrors and show the information for the user in the page referenced by the defaultRedirect attribute, but that would require me to add this error page to every single web project (rather than having everything nicely centralized in one library function).

Is it possible to do regular error handling in Application_Error, but still allow it to be overridden by <customErrors>? Is that even best practice or am I doing something fundamentally wrong?

PS: Many of our applications are hosted on our customer’s servers (instead of our own), so “put all information in the application log and show nothing to the user” is not really an option.


Solution: Replace httpApp.Server.ClearError() with

If Not HttpContext.Current.IsCustomErrorEnabled Then httpApp.Server.ClearError()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:09:20+00:00Added an answer on May 17, 2026 at 3:09 pm

    Personally most of the time I see people opting for an approach similar to what you are doing. There are a number of benefits to doing things your way.

    1. Errors are no longer written to the Application Log in windows, this helps to ensure that clutter/overhead is minimized.
    2. You have an easy to deploy method to add your logging, as you mentioned.

    There are a number of workarounds that I have noticed people using in the past, but the most common is for users to make their custom handler be aware of the CustomErrors setting. So, basically your code would look at the response code that it wants to sent, then take action based on the custom errors. That gets the best of both worlds really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently doing some GUI testing on a ASP.net 2.0 application. The RDBMS is
I'm currently doing the following to use typed datasets in vs2008: Right click on
i'm currently doing some reports for SSRS, and i just confirm what i already
I am currently doing IE-hacks on a website I'm working on: http://www.timkjaerlange.com/wip/co2penhagen/ I got
I am currently doing some socket programming using C/C++. To be able to use
I am currently doing a code review and the following code made me jump.
As I am currently doing this project in only C, I've up untill this
I'm currently doing something like this in some code I'm working on right now:
We're currently doing some Word automation, and want to be able to insert a
Currently I'm doing some unit tests which are executed from bash. Unit tests are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.