C# sharepoint 2010,异常处理httpmodule不工作
我编写了以下HTTP模块来捕获所有异常:C# sharepoint 2010,异常处理httpmodule不工作,c#,.net,sharepoint,exception,module,C#,.net,Sharepoint,Exception,Module,我编写了以下HTTP模块来捕获所有异常: namespace Code.CapEx.Web.Framework.Http.Modules { public class ExceptionHandlingModule : IHttpModule { public void Init(HttpApplication context) { context.Error += OnError; } private static void OnError
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");
}
}
}
}
它可以在我的开发机器上完美地工作(没有sharepoint),并且可以捕获所有异常
但在QA机器上,该网站在sharepoint 2010文件夹下工作,根本不会捕获异常
问题的根源是什么?
(我没有忘记在web.config;)中注册http模块。当SharePoint中发生异常时,它大部分时间由SharePoint处理,然后用户被重定向到包含异常详细信息的SharePoint错误页面。请调查这是否是你的情况 为了更准确地理解我所说的,请看一下这些方法
SPUtility.TransferToErrorPage(…)以及它们在SharePoint中的使用方式。可能会捕获异常,但不会执行重定向,用户可以查看异常详细信息。