Page reference in custom IExceptionHandler

Topics: Exception Handling Application Block
Nov 13, 2007 at 8:12 AM
Edited Nov 13, 2007 at 11:25 AM
Hi misters,

I have an application web ( and I want define custom Handler for exceptionhandling (Enterprise Library)

My custom class..
public class GestorExcepcionesIU : IExceptionHandler

I want to do like this:

Exception IExceptionHandler.HandleException(Exception exception, Guid handlingInstanceId)
RegisterStartupScript(@@@PAGE@@@, "jsExcepcionIU", "alert('Error IU: " + exception.Message.Replace("'", " ") + "');");
return exception;

How I get reference of Page in the custom handler ?

Any help will be appreciated, and I'll be very grateful. Thanks in advance.
Greetings, regards.

SOLUTION: using HttpContext.Current.Handler property. Important: the value of this property can be null or not Page type (in .ashx for example).

Page page = HttpContext.Current.Handler as Page;
if (page != null)
// do something
RegisterStartupScript(page, "jsPoliticaExcepcionIU", "alert('Error Politica IU: " + exception.Message.Replace("'", " ") + "');");

Nov 13, 2007 at 10:06 AM

I'm not sure what PAGE is in your context. Is it an instance, or a type?
Anyway, you can only get data that is either global or included in your exception. What's the case in your scenario?

Apr 26, 2010 at 6:54 PM

Using HttpContext.Current.Handler as Page;