我有 mvc 3 应用程序,当在代码中抛出标准泛型 throw new Exception 时,会显示来自 Views\Shared\error.cshtml 的错误页面。这是通过简单的设置来完成的 <customErrors mode="On"/>.
(这是预期的和期望的)
该应用程序在中间层使用 WCF 服务,当这些服务生成 FaultException MVC 时,它不会显示错误页面,而是在屏幕上显示对用户的 Web 服务调用的详细信息。我要做的就是处理我的代码中的错误并向用户显示Error.cshtml。我曾尝试更改全局 asax,但这确实有效。
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception.GetType() == typeof(FaultException))
{
throw new Exception("There was a fault exception that i do not want to show details of to user.");
}
}