开发者

Show alert message box from the Global.asax (on Application_Error event)

Normally I just redirect to a custom error page in on the Application_Error event, but I have a specific error for which I'd like to display an alert message while the user is still on the page which triggers the error. How can I make this happen?

I'm open to a modalpopup or any other type of error message, I just want to ensure the user stays on the page where they encounter the error.

Thank for any ideas.

This is in reference to this thread: A potentially dangerous Request.Form value was detected: Dealing with these errors proactively,开发者_如何学Go or after the fact

Here is the code I'm currently using:

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


If you know where the error occurs, wrap it in a try-catch block and handle it in the code behind page load.

If you want a Javascript styled modal pop-up error, in the catch, write out a flag value / error message to a hidden variable on the page and handle it in the html document load.


I couldn't figure out an easy way to do this, so I just made new error page for these types of errors, and Redirect to that page when that specific error is caught in the Application_Error event (as my code in the first post indicates).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜