如何在 WebForms 的自定义错误页面中显示异常消息?

发布于 2025-01-14 08:25:26 字数 936 浏览 5 评论 0原文

我在 webforms 中编写了一段代码,用于重定向到 web.config 文件中的自定义错误页面。

 <customErrors mode="On" defaultRedirect="~/ErrorPages/Oops.aspx">
      <error statusCode="500" redirect="~/ErrorPages/StatusCode500.aspx" />
    </customErrors>

我写了一个代码,它给了我数据库错误。

输入图片这里的描述

和 StatusCode500 的代码是:

 <div class="d-flex justify-content-center">
            <h1 style="color: #00AEC0">Oops..Could not connect to Database. </h1>
        </div>
          <div class="d-flex justify-content-center">
            <h4 style="color: #00AEC0">Please contact your Network Administrator</h4>
        </div>

它工作得很好,但现在我需要的是我需要将异常消息(在本例中除以零错误)传递到下面的 StatusCode500 页面请请与您的网络管理员联系。我如何传递异常消息或错误 ID?

I have written a code in webforms to redirect to the custom error page in web.config file.

 <customErrors mode="On" defaultRedirect="~/ErrorPages/Oops.aspx">
      <error statusCode="500" redirect="~/ErrorPages/StatusCode500.aspx" />
    </customErrors>

And I have written a code which gives me database error.

enter image description here

and the code for StatusCode500 is:

 <div class="d-flex justify-content-center">
            <h1 style="color: #00AEC0">Oops..Could not connect to Database. </h1>
        </div>
          <div class="d-flex justify-content-center">
            <h4 style="color: #00AEC0">Please contact your Network Administrator</h4>
        </div>

It works absolutely fine, but now what I need is I need to pass the exceptional message (Divided by zero error in this case) to the StatusCode500 page just below Please contact you network administrator . How can I pass that exceptional message or Error Id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文