Roy Shoa
Roy Shoa

Reputation: 3195

VB.NET Custom Errors Messages

I like to user custom errors in my site. The Idea is to trap errors and display friendly meaningful messages to users. The real error details (line number, Page ...) will sent to me by e-mail. I am programming in VB.NET. Until now every code that i found about this say's that i must use the global.asax for it. I do not like to use global.asax, I just like to make an error page that will sent me a -email with all the error details. Until now, i go to the web.config file and insert this line:

<customErrors defaultRedirect="test.aspx" mode="On"></customErrors>

test.aspx looks like this:

Sub Page_Error(sender as Object, e as EventArgs) Dim ctxOBJ As HttpContext Dim exceptionOBJ As Exception Dim errorInfoTXT As String ctxOBJ = HttpContext.Current() exceptionOBJ = ctxOBJ.Server.GetLastError() errorInfoTXT = "
Offending URL: " & ctxOBJ.Request.Url.ToString() & _ "
Source: " & exceptionOBJ.Source.ToString() & _ "
Message: " & exceptionOBJ.Message.ToString() & _ "
Stack trace: " & exceptionOBJ.StackTrace.ToString() & _ "

Target Site: " & exceptionOBJ.TargetSite.ToString() ctxOBJ.Response.Write (errorInfoTXT) ctxOBJ.Server.ClearError () End Sub

When here is an error in some page its redirect me to test.aspx but not showing any error.

Thanks,

Roy Shoa.

Upvotes: 0

Views: 1475

Answers (1)

BigMomma
BigMomma

Reputation: 338

You just need to change this to

Sub Page_Load(sender as Object, e as EventArgs)

It's not the error page that's erroring, so its error event never fires.

Upvotes: 1

Related Questions