【问题标题】:sharepoint 2010, exception handling httpmodule not workingsharepoint 2010,异常处理 httpmodule 不起作用
【发布时间】:2012-02-28 18:28:50
【问题描述】:

我编写了以下 HTTP 模块来捕获所有异常:

namespace Code.CapEx.Web.Framework.Http.Modules
{
  public class ExceptionHandlingModule : IHttpModule
  {
    public void Init(HttpApplication context)
    {
      context.Error += OnError;
    }

    private static void OnError(object sender, EventArgs e)
    {
      var exc = HttpContext.Current.Server.GetLastError();
      ProcessException(exc.InnerException);
    }

    private static void ProcessException(Exception exception)
    {
      HttpContext.Current.Items["LastError"] = exception;
      EntLogger.Instance.Error(exception);

      if (exception is PermissionsException)
      {
        HttpContext.Current.Response.Redirect("~/_layouts/MyProject/NotAuthorized.aspx");
      }
      else
      {
        HttpContext.Current.Server.Transfer("~/_layouts/MyProject/Error.aspx");
      }
    }
  }
}

它在我的开发机器上完美运行(没有共享点)并且真正捕获所有异常。

但在 QA 机器上,此站点在 sharepoint 2010 文件夹下工作,根本不会捕获异常!

问题的根源是什么? (我没有忘记在 web.config 中注册 http 模块;))

【问题讨论】:

  • 可能捕获到异常,但不执行重定向,用户可以看到异常详情。

标签: c# .net sharepoint exception module


【解决方案1】:

当 SharePoint 中发生异常时,大多数时间由 SharePoint 处理,然后将用户重定向到包含异常详细信息的 SharePoint 错误页面。请调查是否是您的情况。

要更准确地理解我在说什么,请查看方法 SPUtility.TransferToErrorPage(...) 以及它们在 SharePoint 中的使用方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    相关资源
    最近更新 更多