Running code before Page_Error

S

slolife

What I am trying to do is handle the HttpRequestValidationException
with code, but only on pages that are equipped to handle it with
special customvalidators, controls, etc.. But what I cannot seem to
find is where to put some code in my derived page that sets a property
in the base page class that tells the base Page_Error to deal with
HttpRequestValidationException.

See the code below.

Here's my base page:

Public Class BasePage
Inherits System.Web.UI.Page

Protected m_CatchHttpRequestValidationException As Boolean

Private Sub Page_Error(s Object, e As EventArgs) Handles
MyBase.Error
If Me.m_CatchHttpRequestValidationException Then
If Server.GetLastError.GetType() Is
GetType(HttpRequestValidationException) Then

HttpContext.Current.Items("HttpRequestValidationException") = True
Server.ClearError()
End If
End If
End Sub
End Class

Here's my derived page:

Partial Class TestPage
Inherits BasePage

Private Sub Page_PreInit(s As Object, e As EventArgs) Handles
MyBase.PreInit
Me.m_CatchHttpRequestValidationException = True
End Sub

Private Sub Page_Init(s As Object, e As EventArgs) Handles
MyBase.Init
Me.m_CatchHttpRequestValidationException = True
End Sub


Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load
Me.m_CatchHttpRequestValidationException = True
End Sub

End Class

Anyone know where to put page code to run before Page_Error occurs and
is called?

Thanks
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top