2012-02-28 75 views
0

我已經寫了下面的HTTP模塊捕獲所有異常:SharePoint 2010中,異常處理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"); 
     } 
    } 
    } 
} 

它完美我的開發機器上(沒有的SharePoint),真正捕獲所有異常。

但在質量保證機器上,本站在sharepoint 2010文件夾下工作,異常不會被捕獲!

什麼是問題來源? (我沒有忘記在web.config中註冊http模塊;))

+0

可能發生異常,但不執行重定向,用戶可以看到異常詳細信息。 – Ruslan 2012-02-28 18:31:00

回答

0

當SharePoint發生異常時,大部分時間由SharePoint處理,然後用戶重定向到SharePoint錯誤頁面例外的細節。請調查這是你的情況。

要理解我在說什麼更精確地看看方法 SPUtility.TransferToErrorPage(...)以及它們在SharePoint中的使用方式。