7-23錯誤處理&資料緩衝

來源:互聯網
上載者:User

1 頁面的Error事件

private void WebForm1_Error(object sender, System.EventArgs e)
        ...{
            Response.Write(Server.GetLastError().Message);
            Server.ClearError();
        }

 2 Global.asax.cs裡的Application_Error事件

protected void Application_Error(Object sender, EventArgs e)
...{
          Response.Redirect("Error.aspx?msg=" + Server.GetLastError().Message);
          Server.ClearError();
}
Request.QueryString的用法

 3 web.config中的<customErrors mode="RemoteOnly"/>

 <!--  自訂錯誤資訊
          設定 customErrors mode="On" 或 "RemoteOnly" 以啟用自訂錯誤資訊,或設定為 "Off" 以禁用自訂錯誤資訊。
          為每個要處理的錯誤添加 <error> 標記。

          "On" 始終顯示自訂(友好的)資訊。
          "Off" 始終顯示詳細的 ASP.NET 錯誤資訊。
          "RemoteOnly" 只對不在本地 Web 服務器上啟動並執行
           使用者顯示自訂(友好的)資訊。出於安全目的,建議使用此設定,以便
           不向遠程用戶端顯示應用程式的詳細資料。
    -->

<customErrors mode="On" defaultRedirect="Error.aspx"> 設定defaultRedirect 需要將mode設定為On

 <customErrors mode="On" defaultRedirect="Error.aspx">
           <error statusCode="404" redirect="Error.aspx?msg=你所訪問的頁面不存在或已被刪除"/>
  </customErrors>

4 Document的屬性trace頁層級跟蹤

 

        private void btnTest_Click(object sender, System.EventArgs e)
        ...{
                                   this.Trace.Write("btnTest_Click","變數的值");
        }
        private void chk_CheckedChanged(object sender, System.EventArgs e)
        ...{
                 this.Trace.Warn("chk_CheckedChanged","CheckedChanged");//顯示紅色
        }

TraceMode="SortByTime"或者"SortByCategory" //Category種類

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.