How can I customize the error view to display user-friendly messages instead of technical details?

Question

Grade: Education Subject: Support
How can I customize the error view to display user-friendly messages instead of technical details?
Asked by:
98 Viewed 98 Answers

Answer (98)

Best Answer
(438)
In your `Error.cshtml` view, avoid directly displaying the `ViewBag.Error` object, which often contains technical details like stack traces. Instead, create user-friendly error messages based on the exception type or status code. You can use conditional logic (e.g., `if (ViewBag.Error is Http404NotFoundException)`) to display specific messages for different error scenarios. Consider providing helpful links or suggestions to the user.