在弹出窗口中显示所有异常而不是在 MVC 4 中重定向用户的最佳方法是什么?

What is the best way show all exceptions in a popup instead redirect the user in MVC 4?

我在 .Net MVC 4 中有一个 Web 应用程序。该应用程序使用区域,每个区域都有自己的自定义基础控制器。我想将所有异常集中在一个地方并处理每一个异常并重定向到带有折叠 div 和详细信息的弹出视图。 是否有一些设计模式或示例?

看看 this 文章。

有很多方法可以做到。

我的首选方法是从 link:

覆盖 Global.asax
public class MvcApplication : System.Web.HttpApplication
{
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();
            Server.ClearError();
            Response.Redirect("/Home/Error");
        }
}

这样,逻辑只写一次

不过,当通过 AJAX 发出请求时,您可能希望区分错误。应该很难,因为那里有请求上下文,here 是一个完整的解决方案。