【发布时间】:2017-07-09 08:04:01
【问题描述】:
在 Web.config 和 Index.aspx 中使用错误处理我正在使用 try and catch 错误处理。如何在基于 Web.config 的 Index.aspx catch { } 中捕获错误。
Web.config
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="404" redirect="404.aspx" />
<error statusCode="500" redirect="500.aspx" />
</customErrors>
索引.aspx
try {
}
catch {
How to trigger error handling in custom error?
}
【问题讨论】:
-
我假设您只想重定向到捕获中的“error.aspx”?如果是这样,你不能只做 Response.Redirect("Error.aspx") 吗?尽管您的问题有点不清楚,但也许您可以准确解释一下您要在 catch 中做什么?
-
在catch { }中我想捕获错误并根据
中的错误代码自动显示错误页面 -
您将不得不编写一些代码。这不是通过将您的逻辑包装在 try and catch 或添加几行配置而自动发生的事情。这里解释了 web config 404 stackoverflow.com/questions/4483849/…