2012-12-02 44 views
1

我在Global.asax中添加自定義錯誤異常。它工作在調試模式,但是當我在IIS 7.0中發佈它不工作: 的Global.asax: 重定向在Global.asax中無效發佈時間

void Application_Error(object sender, EventArgs e) 
    { 
    // Code that runs when an unhandled error occurs 
     //Ramezani V4.5: Change0002 29-08-91   
     if (Context.AllErrors[0].InnerException != null) 
     { 
      try 
      { 
       bool IsValid = (Session["ExceptionHandler"] == null); 
       ArisFramWork.ExceptionHandler handler = new ArisFramWork.ExceptionHandler(Request.AppRelativeCurrentExecutionFilePath, (Context.AllErrors[0] == null ? new Exception("No Error Found") : Context.AllErrors[0])); 
       Session["ExceptionHandler"] = handler; 
       string redirectURL = (IsValid ? Request.AppRelativeCurrentExecutionFilePath : "~/ExceptionHandler.aspx"); 
       Response.Redirect((Request.QueryString.Count == 0 ? redirectURL : redirectURL + "?" + Request.QueryString.ToString()));  
      } 
      catch 
      { 
       Session["ExceptionHandler"] = null; 
      } 
     } 
     else 
     { 
      Response.Redirect("~/FileAccess.aspx"); 
     } 
    } 
void Application_Start(object sender, EventArgs e) 
    { 
     FastReport.Utils.Config.WebMode = true; 
     // Code that runs on application startup 
     //Ramezani V4.5: Change0002 29-08-91  
     //if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)  
      Session["ExceptionHandler"] = null; 
    } 

在ExceptionHandler.aspx:

protected void Page_Load(object sender, EventArgs e) 
    { 
     try 
     { 
      publicclass.MessageBox("Hello ExceptionHandler", this); 
      if (Session["ExceptionHandler"] != null) 
      { 
       if(ExceptionHandlerBulletedList.Items.Count==1) 
        ExceptionHandlerBulletedList.Items.RemoveAt(0); 
       List<ArisFramWork.ExceptionHandler> ExecutionCollection = (List<ArisFramWork.ExceptionHandler>)Session["ExceptionHandler"]; 
       if (ExecutionCollection.Count < 1) 
       { 
        Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "CloseForm", "window.close();", true); 
        return; 
       }  
       ..... 
       Session["ExceptionHandler"] = null; 
      } 
     } 
     catch (Exception exception) 
     { 
      Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "CloseForm", "window.close();", true); 
     } 
    } 

當我在調試模式下運行的網站通過Visual Studio 2010它是工作,但它不會重定向到ExceptionHandler.asax在發佈模式

+0

還有o答案呢!我無法解決這個問題。當我使用IIS 5.0時,IE 6.0可以正常工作!!!!! – user1020565

回答

0

這是因爲global.asax文件未發佈。手動將該文件複製到發佈的文件夾中。

如果這是一個Web應用程序項目,那麼您可以將global.asax文件屬性設置爲內容。不幸的是,如果它是網站,那麼你必須手動做到這一點。

我仍然打破了我的腦海如何將global.asax納入發佈列表。還沒有答案。

global.asax works on local computer but not after i publish to server

+0

親愛的Esen,我做到了,但沒有工作 – user1020565

+0

請確保您的網站下有PrecompiledApp.config文件。 – Esen