我在我的 MVC 应用程序中设置了 ELMAH,如果抛出异常,我想显示一个友好的屏幕。但是我仍然得到 YSOD。所以在我的 web.config 中我有(我也尝试了其他模式但没有成功)。我的错误控制器有命名空间 ITOF.Controllers { using System.Net; 使用 System.Web.Mvc;
public class ErrorController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Unknown()
{
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return View("Unknown");
}
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult NotFound(string path)
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("NotFound", path);
}
}
}
这些方法在 mode="On" 时被调用
但是,然后我得到一个运行时错误 YSOD,它告诉我更改我的 web.config customError mode="RemoteOnly"
也许我的视图中有错误?
他们来了;
未知的.cshtml;
@{
ViewBag.Title = "Error";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Sorry, an error occurred while processing your request.</h2>
未找到.cshtml;
@{
ViewBag.Title = "Not Found";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Lost?</h2>
<p>Sorry - your request doesn't exist or was deleted.</p>