Once you create a
WebPage
you automatically derive from
System.Web.UI.Page
. The Page object helps you trap page-level errors. In order to perform this you need to override it's
OnError
method.
protected override void OnError(EventArgs e)
{
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError ();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString () +
"<br>Source: " + exception.Source +
"<br>Message: " + exception.Message +
"<br>Stack trace: " + exception.StackTrace;
ctx.Response.Write (errorInfo);
ctx.Server.ClearError ();
base.OnError (e);
}
Regards