【ASP.NET定製錯誤頁】

來源:互聯網
上載者:User
定製錯誤頁Error.html

錯誤頁可以避免程式拋異常的時候泄露有可能引發安全問題的可能性,只給使用者查看錯誤頁面的機會,5秒鐘以後會自動跳轉到首頁。

具體做法如下:

  1. 在項目中建立一個錯誤頁:Error.html
  2. 在其head部分加入一下一段js代碼
    <script language="javascript" type="text/javascript">        var i = 5;        var intervalId;        intervalId = setInterval("fun()", 1000);        function fun() {            if (i == 0) {                window.location.href = "Default.aspx";                clearInterval(intervalId);      /* 避免顯示負值,清除yTimer */            }            document.getElementById("mes").innerHTML = i;            i--;        }    </script>

HTML代碼如下:

<h3>出錯啦~~~~</h3>        <div id="error">            <img src="images/error.gif" alt="error" />            <p>系統出錯啦~~~,請聯絡管理員!</p>            <p>將在 <span id="mes">5</span> 秒中後 返回首頁</p>        </div>

3.  配置Web.config檔案
在<system.web>標籤中加入

<!-- 出現錯誤的時候自動定向 -->        <customErrors mode="On" defaultRedirect="~/Error.htm"></customErrors>

4.  到此,錯誤頁定製完成。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.