Show full error messages when hosting MVC application on IIS 7.5
I am deploying a MVC3 application on IIS 7.5.
There are some errors which only occur on IIS 7.5, and I am attempting to debug them. However, whenever an error is triggered, the default error.cshtml is shown.
Is it possible to show detailed error messages, similar to how errors are handled in Visual Studio开发者_Python百科 2010?
How do I pass in exception details to error.cshtml when using the OnHandleError attribute?
Your Error.cshtml
view should accept a model of type HandleErrorInfo
. You can get the exception detail from the Model.Exception
property.
For example, your view might look like:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Uh-oh, an error occurred/";
}
<h2>One of us broke the site!</h2>
@if (Model != null)
{
<h3>@Model.Exception.GetType().Name</h3>
<pre>
@Model.Exception.ToString()
</pre>
<p>
thrown in @Model.ControllerName @Model.ActionName
</p>
}
If this is for debug purposes you can turn off custom errors in your web.config or set to remote so you can view the details while debugging.
You can also wrap it in a check to make sure that Debugging is turned on and always display it in HTML comments (so it's not plainly visible to anyone browsing the site). E.g
@if (System.Web.HttpContext.Current.IsDebuggingEnabled)
{
<!--
<P>@Model.Exception.ToString()</P>
-->
}
精彩评论