Last active
December 19, 2015 09:29
-
-
Save harrybiscuit/5933339 to your computer and use it in GitHub Desktop.
Custom error handling with .net MVC 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyController : Controller | |
{ | |
[HandleError(View ="MyCustomError",ExceptionType = typeof(MyException))] | |
public ActionResult MyAction(string SaleType) | |
{ | |
//Do stuff here that may throw an exception | |
// The following line will demonstrate what happens when an exception is thrown | |
throw new MyException("bang !"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model HandleErrorInfo | |
<h2>Custom Error</h2> | |
<p>We apologise for the inconvenience. You are seeing this page because an error occurred while processing your request</p> | |
<p>We have recorded this error and the team periodically review any errors in an effort to improve our service. </p> | |
<p>We really value your help and feedback in resolving these issues. Nothing makes us happier than producing high quality and reliable software</p> | |
<hr/> | |
<p>The stuff below is technical information to help the support team find out what went wrong. If you are not in the support team you can safely ignore this.</p> | |
<p> | |
<b>Controller</b>: @Model.ControllerName <br> | |
<b>Action</b>: @Model.ActionName <br> | |
<b>Exception</b>: @Model.Exception | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<system.web> | |
<customErrors mode="On"/> | |
</system.web> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment