Skip to content

Instantly share code, notes, and snippets.

@harrybiscuit
Last active December 19, 2015 09:29
Show Gist options
  • Save harrybiscuit/5933339 to your computer and use it in GitHub Desktop.
Save harrybiscuit/5933339 to your computer and use it in GitHub Desktop.
Custom error handling with .net MVC 3
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 !");
}
}
@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>
<?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