Best strategy for all errors?

M

Marty McDonald

Many of our apps are in production and they do not have proper error logging
in them - unhandled errors are seen by the users in the form of error
messages and stack traces. I know how to make apps handle their errors
(global.asax.cs "application_error" event, web.config "customErrors"
section, etc). But can I do this without having to visit each app? Can
this be done at the machine level? I'm looking for a kind of machine-level
"application error" event that will handle any untrapped errors. How is
this done? Thanks! --Marty
 
S

Steven Cheng[MSFT]

Hi Marty,


Thanks for posting in the community!
From your description, you'd like to provide a more friendly error
displaying view(a custom error screen) for the client user rather then the
system's exception detailed info page when unhandled exceptions occurs in
ASP.NET web applicatoin. Also, you want to find some place to configure it
at machine level rather than configure it everytime in a certain web
application, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my experience, you can try using the <customErrors > element in
the ASP.NET 's web application configuration schema. There is a "mode"
attribute in the <customErrors> element, we can set it to control whether
to show the detailed error info page or redirect user to the custom error
page (set via the "defaultRedirect" attribute). For example:

<customErrors defaultRedirect="mycustomererrorpage.htm" mode="On">
</customErrors>

The above setting told the ASP.NET runtime when unhandled error occurs,
don't show the detailed exception info page( because we set the "mode=On"),
and redirect the user to the custom error page(we set in the
"defaultRedirect" attribute).
Here is the detailed description of the "mode" attribute in MSDN:

On-------------------- Specifies that custom errors are enabled. If no
defaultRedirect is specified, users see a generic error.

Off -------------------Specifies that custom errors are disabled. This
allows display of detailed errors.

RemoteOnly -------------------Specifies that custom errors are shown only
to remote clients and ASP.NET errors are shown to the local host. This is
the default.

For detailed info of the <customErrors> configure tag, you can view the
following tech reference in MSDN:
#<customErrors> Element
http://msdn.microsoft.com/library/en-us/cpgenref/html/gngrfCustomerrorsSecti
on.asp?frame=true

This error handling setting can be configured in both web.config file(web
application level) and machine.config(machine level). Since you want to set
it for all web apps on a certain machine, you can find the <customErrors>
tag in the machine.config file and set it. For example, if you want to
prevent client user from seeing the detailed exception info page. You can
set the <customErrors> tag in machine.config as below:
<customErrors defaultRedirect="customErrorPage.html" mode="RemoteOnly">
</customErrors>

Then, you also need to have a "customErrorPage.html in each web
application. After that, each time unhandled exception occurs in a web
application, the remote user will see the customErrorPage.html rather than
the detailed exception info page. But the localuser can still see the
detailed error info page. How do you think of this?

In addition, here is some other tech aritcles on ASP.NET configuration and
providing custom error report page:

#INFO: ASP.NET Configuration Overview
http://support.microsoft.com/?id=307626

#HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C#
.NET
http://support.microsoft.com/?id=306355

#Rich Custom Error Handling with ASP.NET
http://msdn.microsoft.com/library/en-us/dnaspp/html/customerrors.asp?frame=t
rue

I believe they're also helpful to you. Please check out the above
suggestions. If you feel anything unclear, please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Marty,


Have you had a chance to try out my suggestions or have you got any ideas
on this issue? If you need any assistance, please feel free to post here.




Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top