Display specific error message on custom error page - asp.net

I know it's possible in asp.net to create a custom error page in a web app, by putting the following line in the web.config:
<customErrors mode="RemoteOnly" defaultRedirect="frmErrorPage.aspx" />
I have had to do this for my web app, since it is clearly much tidier than letting the program bomb out with it's ugly default error page. My custom error page just has the customer's logo and a brief message saying "Error has occurred. Please return to homepage"
The trouble now is that I have no way of knowing what caused the error, when a customer reports it.
Is there a way to make the actual error message appear on this custom error page too?

You should be using logging to know when/where/what errors occured. The POINT of the custom error page is to not allow the end user to see why it messed up because obviously that could be a security risk. Look into using ELMAH. It automatically creates a nice web gui for any uncaught exceptions. And you can also create logs when you catch the errors yourself.
If you do chose to use ELMAH, I would also strongly recommend installing it with the NuGet package manager

Related

errors with the php filter module

When I purposefully throw a php error from within embedded php code in the php filter module, Drupal displays the message The website encountered an unexpected error. Please try again later.
We like to send users with unanticipated programmer errors to an error handling page so that they don't land on a dead error page without us getting notified, so I'm trying to find out how to intercept this in Drupal. I've tried searching within Drupal for where this error string gets outputted, with no luck.
How exactly does Drupal handle errors occurring within embedded php code, or more directly: how can I make it redirect to another page or catch the error in another way?
Thanks
That specific error comes as a result of Drupal explicitly setting the PHP exception handler to a custom function (done in _drupal_bootstrap_configuration()).
The exception handler itself is _drupal_exception_handler(), which invokes _drupal_log_error(), and that's where the error page is generated.
I've never tried it, but I reckon you'd get away with implementing hook_boot() and using set_exception_handler() to provide your own implementation of the core Drupal functions to theme that error page differently.
It might seem a bit of a long way round but since _drupal_error_log() doesn't invoke any hooks (it probably happens too early on for that anyway) I can't see any other way to do it without editing the core files.

Display Custom Error Page for All Errors in IIS

I have a few sites in my IIS including ASP.Net and PHP. I want to define a custom pages for error handling that I can configure in IIS and it displays on errors occuring in all the sites. Say for example if error 500 is occured it displays an ASP.Net page having detailed error info of what happened actually. Is that possible?
No. = (
PHP
For your PHP sites, there are different solutions including error-logging plugins, but the standard one involves the built-in functionality of PHP's error handling. See here: http://www.nyphp.org/PHundamentals/7_PHP-Error-Handling
ASP.NET
For ASP.NET sites, this is the default behavior of the IIS error page. It will show you the exact error code, stack trace, and offending lines of code. If you wanted to, you could create your own application-level error handler to handle any and all exceptions that can occur inside your site; usually this is used to hide the nasty error message and show the user a friendlier, less-scary message instead. You can certainly re-use the code in all your different ASP.NET sites. See: http://www.codeproject.com/Articles/5977/Global-Error-Handling-in-ASP-NET

SharePoint Server 2010: Problem getting detailed error messages

I'm pretty new to SharePoint and IIS, but I haven't been able to find an answer to this one. I'm deploying a custom ASPX with code-behind to my SharePoint server and need a detailed stack trace to see where my problems are.
This involves modifying the web.config file and setting three attributes of certain tags: <SafeMode CallStack="true" AllowPageLevelTrace="true" /> and <CustomErrors mode="Off" />. There are lots of different web.config files, but my error messages change when I modify a certain one, indicating that I chose the right file to edit.
Error message
The problem, however, is that when I do change these tags, I only get an error message telling me the stack trace cannot be displayed remotely, even if I try to display the page on the server itself. The error message basically tells me that in order to get the complete stack trace, I have to do what I just did: Set CustomErrors mode="Off".
I have had this happen before, but only with certain types of errors (HttpModules).
Try checking the windows event log for a more detailed message. It should be there.
Also try restarting IIS/server to make sure its clean/all services are started.

ASP.NET Custom Errors vs. Compilation debug="false" and security

I keep reading that an ASP.NET based web site should have custom errors enabled in the web.config because exceptions will show a stack trace.
I may have a faulty memory (currently don't have access to an ASP.NET website under development), but I thought as long as Compilation debug="false" in the web.config file, then the stack trace will not be displayed.
Is my understanding correct about the debug flag and display of the stack trace? If so, then even if custom errors are not enabled, then won't the only message displayed to remote users for an exception be a the non-descriptive message:
"The page cannot be displayed because an internal server error has occurred."
If so then wouldn't it be OK, from a security perspective, to not display a custom error page for the exception?
No, a stack trace will still be shown even if the debug flag is off, but it will not have line numbers for each call in the stack.
The non-descriptive message is what the browser usually shows instead of the actual error message from the server, unless you change the configuration. Anyone wanting to expose information by causing error messages would know how to do this.
Displaying the stack trace isn't a security risk in itself, but it does expose some information that could potentially make it easier to hack the site. A hacker might for example get a clue as to what's done to sanitase the input and find a way around it.
Custom error messages should almost always be prefered over the default error thrown. It gracefully sends your user to a location where they can keep browsing your site without having to go back and try again.
Turning DEBUGGING off in your web.Config is VERY important and goes beyond just not showing the line numbers and stack trace... it also tells the compiler to build in release mode which optimizes performance dramatically. As soon as your app goes to production, all debugging should be disabled.

Design Pattern for error handling in ASP.NET 3.5 site

I am relatively new to ASP.NET programming, and web programming in general. We have a site we recently ported from .NET 1.1 to 3.5. Currently we have two methods of error handling: either catching the error during data load on a page and displaying the formatted error in a label on the page, or redirecting to a generic error page. Both of these are somewhat annoying, as right now I'm trying to redesign how our errors are displayed.
We are soon moving to Master pages, and I'm wondering if there is a way to "build in" an error handling control. What I mean by this is using a ASP.NET user control I've designed that simply gets passed the error string returned from the server. If an error occurs, the page would not display the content, and instead display the error control. This provides us with the ability to retain the current banner/navigation during an error (which we don't get with the generic error page), as well as keeping me from having to add the control to every aspx page we have (which I have to do with using the label-per-page system). Does something like this make sense? Ultimately I just want to have the error control added to a single page, and all other pages have access to it directly. Is this something Master pages help with?
Thanks!
User the application_error event in the global.asax to catch all your unhandled errors - you can log them here. You shouldn't be outputting error messages to the client like this.
Use the CustomErrors section in the web.config to define a custom error page for your users to get.
You could also look at using something like ELMAH for easy loggin.

Resources