I'm currently working on an MVC application. My issue is that I can't get my customerror handling to work correctly.
So essentially what happens is I throw an exception to test this in a controller. Then the application should redirect the user to ~/Shared/Errors.cshtml but for some reason it doesn't do this.
Here is the code.
Exception being thrown:
throw new Exception("Something went wrong");
Webconfig file:
<customErrors mode="RemoteOnly"/>
ErrorController Code:
public class ErrorController : Controller
{
//
// GET: /Error/
public ActionResult Index()
{
return View();
}
}
Code used in Error.cshtml:
@model System.Web.Mvc.HandleErrorInfo
@{
Layout = "_Layout.cshtml";
ViewBag.Title = "Error";
}
<div class="list-header clearfix">
<span>Error</span>
</div>
<div class="list-sfs-holder">
<div class="alert alert-error">
An unexpected error has occurred. Please contact the system administrator.
</div>
@if (Model != null && HttpContext.Current.IsDebuggingEnabled)
{
<div>
<p>
<b>Exception:</b> @Model.Exception.Message<br />
<b>Controller:</b> @Model.ControllerName<br />
<b>Action:</b> @Model.ActionName
</p>
<div style="overflow:scroll">
<pre>
@Model.Exception.StackTrace
</pre>
</div>
</div>
}
</div>
Thanks in advance for any help you can give