Convert System.Exception into friendly HTML in ASP.NET MVC and C#
I'd like to present my exception to my advanced users in a nice HTML way.
Is there any convenient way (using library, or small amounts of code) to convert the details of an System.Exception (and inner exceptions) into nice presentation HTML?
I've tried looking at the ELMAH code base but it seems to use the older HTMLWriter for building the HTML document.
I 开发者_StackOverflowwas hoping to find something a bit simpler.
Any help is greatly appreciated.
The best way to present Exceptions to users (even advanced users) is to not present them at all. Simply present the user with a well formatted error page explaining that something went wrong, you logged the error, and you'll look in to it.
There are two problems with giving users details about the Exception that occurred:
Reveals details about the implementation of your software which could, theoretically, be exploited by malicious users.
Users (even Advanced Users) can't do anything about the Exception when it happens. They're still just users. Why give somebody details about a problem that they can't do anything about?
You can create a hierarchy of the domain-specific exceptions that derive from System.Exception.
Usually, these exceptions will only provide non-technical simple meaningful to the user error message. Behind the scene you will log the exception with all the tech details.
精彩评论