【发布时间】:2014-05-09 09:45:23
【问题描述】:
我有一个启用了 customErrors 的网站,它会将我引导至自制视图。但是如果出现服务器错误,我想在 SorryPage 视图上显示堆栈跟踪。为什么?因为这样用户可以复制粘贴错误并将其发送到我们公司的 IT 帮助台,这样我们就知道出了什么问题以及错误来自哪里。
我以前见过这个,但不知道该怎么做。非常感谢任何帮助!
控制器:
public ActionResult SorryPage()
{
return View("Error", new ErrorModel(ErrorMessages.SorryPage, "General", "Home", Labels.GoBackToPortal));
}
查看:
@using ILVO.Web.Resources
@model ILVO.Web.Areas.General.Error._Error.ErrorModel
@{
ViewBag.Title = "Error pagina";
Layout = "~/Views/Layouts/_Layout.cshtml";
}
<h1>@Html.Label("Error", Labels.TitleErrorPage)</h1>
<br/>
<h2>@Model.ErrorMessage</h2>
<br/>
<div class="margin-bottom5px">
@Html.ActionLink(Model.Button, "Index", Model.ToController, new { Area = Model.ToArea }, new { @class = "button" })
</div>
型号:
public class ErrorModel
{
public ErrorModel(string errorMessage, string toArea, string toController, string button)
{
ErrorMessage = errorMessage;
ToArea = toArea;
ToController = toController;
Button = button;
}
public string ErrorMessage { get; set; }
public string ToArea { get; set; }
public string ToController { get; set; }
public string Button { get; set; }
}
我的 cfg 文件:
<customErrors mode="RemoteOnly" xdt:Transform="Replace" defaultRedirect="~/General/Error/SorryPage">
<error statusCode="500" redirect="~/General/Error/SorryPage"/>
<error statusCode="404" redirect="~/General/Error/NotFound"/>
</customErrors>
【问题讨论】:
标签: asp.net-mvc error-handling stack-trace