如何尝试并捕获重定向到错误页面?
早上好,
我有一个注册表单,可将用户添加到系统中。例如,当管理员在出生日期中输入字母而不是日期时,就会发生异常。我在 web.config 中执行了以下代码:
"customErrors mode="On" defaultRedirect="Error.aspx""
当错误发生时,try 和 catch 函数如何将管理员重定向到 error.aspx?
Good morning,
I have a registration form which adds the user to the system. For example when the admin enters a letter instead of a date in the date of birth, an exception occurs. I did the following code in the web.config:
"customErrors mode="On" defaultRedirect="Error.aspx""
How the try and catch function will redirect the admin to the error.aspx when the error occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您已经捕获了此异常,因此它不会重定向到错误页面。如果您想这样做,请尝试重新抛出异常。
Since you have captured this exception, it will not redirect to the error page. If you want to do so, please try to rethrow the exception.
听起来您需要捕获异常,然后手动重定向(Response.Redirect)到错误页面。您可以通过会话变量或应用程序变量将异常传递到错误页面。
It sounds like you need to catch the exception then do a manual redirect (Response.Redirect) to your error page. You can pass the exception to your error page in a session variable or application variable.
除非您执行某些操作,否则如果您自己捕获异常,管理页面将不会重定向到 error.aspx。
它只会重定向未处理的异常。
更新
从您的评论来看,您似乎最好在页面上创建某种验证以及验证摘要,而不是依赖重定向到错误页面。你想要两件不能在一起的事情。
Unless you do something, the admin page will NOT redirect to error.aspx if you catch the exception yourself.
it will only redirect for unhandled exceptions.
update
From your comments, it seems you are better of creating some kind of validation on your page together with a validationsummary instead of relying on a redirect to the Error page. You want two things that cannot go together.