【问题标题】:MVC3 Handling of exceptions in catch blocks and throw ExceptionsMVC3 处理 catch 块中的异常并抛出异常
【发布时间】:2013-07-19 11:49:41
【问题描述】:

我想了解如何在 MVC3 中处理特定于休息服务的异常。任何指针? 基本上,我有一个控制器,并且可能有多个 try catch 块和 throw 异常语句。 看完所有帖子后,我有点困惑。 编辑:

public ActionResult Index()
    {
        IConsumerRequest conReq = oSession.Request();
        conReq = conReq.Get();
        conReq = conReq.ForUrl(Session["ServiceEndPoint"].ToString());
        try
        {
            conReq = conReq.SignWithToken();
        }
        catch (Exception ex)
        {
            throw ex;
        }

       return View();
    }

在抛出异常时,我需要能够重定向到自定义错误页面。 我也通读了这篇文章: Custom error pages on asp.net MVC3 但是如果我的应用程序没有在 IIS 上运行,我该如何处理不同的错误代码,例如 302 或其他任何错误代码。

【问题讨论】:

  • 我们能看看你说的一些控制器代码吗?

标签: asp.net-mvc asp.net-mvc-3 exception-handling


【解决方案1】:

Bellow 是自定义 exp 处理的好链接

Click Here

【讨论】:

  • 谢谢,您分享的样本非常好。我肯定会在我的下一个项目中尝试它。现在我使用这种方法实现-forums.asp.net/t/1505777.aspx
猜你喜欢
  • 1970-01-01
  • 2021-10-21
  • 1970-01-01
  • 2012-09-21
  • 1970-01-01
  • 2011-03-18
  • 1970-01-01
  • 2013-07-24
相关资源
最近更新 更多