如何处理在asp.net mvc3中挂起的错误页面?

时间:2022-05-24 03:29:30

I have an error page that uses a Master Page in .Net MVC3. The Master Page needs the controller for the error view to inherit from ApplicationController wich does some essential loading of data for the ViewModel used in the Master Page.

我有一个在。net MVC3中使用母版页的错误页面。主页面需要从ApplicationController wich继承错误视图的控制器为主页面中使用的视图模型执行一些基本的数据加载。

public class ErrorController : ApplicationController
{
    public ActionResult Error()
    {
        return View();
    }
}

But when the ApplicationController gets an error trying to load it's data, the Error page will also hang, because it is dependent on ApplicationController.

但是当ApplicationController试图加载其数据时出现错误时,错误页面也会挂起,因为它依赖于ApplicationController。

As I understand the problem, the best solution would be to have an alternate error page if the error occured in ApplicationController.

根据我对问题的理解,如果错误发生在ApplicationController中,那么最好的解决方案是有一个备用的错误页面。

How would I set an alternate error page to be used if the error occurs in the ApplicationController?

如果错误发生在ApplicationController中,我如何设置要使用的备用错误页?

1 个解决方案

#1


2  

You need to use a Global Error Handler, kind of like Global.asax. Here is a solution you can check out: http://blog.ploeh.dk/2009/12/01/GlobalErrorHandlingInASPNETMVC.aspx

您需要使用全局错误处理程序,有点像Global.asax。这里有一个解决方案:http://blog.ploeh.dk/2009/12/01/globalerrorhandlinginaspnetvc.aspx

Good luck!

好运!

#1


2  

You need to use a Global Error Handler, kind of like Global.asax. Here is a solution you can check out: http://blog.ploeh.dk/2009/12/01/GlobalErrorHandlingInASPNETMVC.aspx

您需要使用全局错误处理程序,有点像Global.asax。这里有一个解决方案:http://blog.ploeh.dk/2009/12/01/globalerrorhandlinginaspnetvc.aspx

Good luck!

好运!