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, 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
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).