【发布时间】:2011-02-07 00:27:54
【问题描述】:
通常我只是重定向到 Application_Error 事件中的自定义错误页面,但我有一个特定的错误,我想在用户仍在触发错误的页面上时显示一条警报消息。我怎样才能做到这一点?
我对 modalpopup 或任何其他类型的错误消息持开放态度,我只是想确保用户停留在他们遇到错误的页面上。
感谢您的任何想法。
这是我目前使用的代码:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) 'Code that runs when an unhandled error occurs Try Dim err As Exception = Server.GetLastError If err.Message IsNot Nothing Then If err.Message = "The client disconnected." Then Dim LogError As New LogError(Server.GetLastError, Session, Request) LogError.LogError() Response.Redirect("~/TimeoutPage.aspx?id=2") ElseIf err.Message.Contains("dangerous Request.Form value") Then 'Response.Redirect("~/MyInputErrorPage.aspx") 'Instead the above redirect, I'd like to show the user an alertbox or something similar to explain the error to them Else Dim LogError As New LogError(Server.GetLastError, Session, Request) LogError.LogError() Response.Redirect("~/MyErrorPage.aspx") End If End If Catch ex As Exception End Try
【问题讨论】:
-
您能否定义需要此功能的特定情况?一旦用户点击某些东西并触发请求,他们就不再真正“在页面上”了。为什么不直接在页面本身添加错误处理?
-
有大量页面可能会触发此错误,我不想更新所有页面..这就是我尝试在 Global.asax 中处理此问题的原因请查看修改后的问题...这是关于在用户输入潜在危险字符(例如 字符)时捕获错误...我不想在每个页面/输入控件上对这些字符进行验证。
标签: .net asp.net vb.net error-handling global-asax