-
May 3rd, 2010, 10:31 AM
#1
Thread Starter
Frenzied Member
send error
Hi,
I would like to know if it's possible if at anytime an error occur on my server, i would like to receive an email with description of the error.
Thanks
-
May 3rd, 2010, 11:04 AM
#2
Thread Starter
Frenzied Member
Re: send error
i was able to do this, But i would like to see exactly what user will see on the error page.
Thanks
vb Code:
Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error Dim loginInfo3 As New NetworkCredential("xxxxx@gmail.com", "xxxxx") Dim msg3 As New MailMessage("xxxx@gmail.com", "xxxx@gmail.com", Server.GetLastError.Message.ToString, Server.GetLastError.ToString) ' msg3.IsBodyHtml = True Dim client3 As New SmtpClient("smtp.gmail.com", 587) client3.EnableSsl = True client3.UseDefaultCredentials = False client3.Credentials = loginInfo3 client3.Send(msg3) End Sub
-
May 3rd, 2010, 01:05 PM
#3
Re: send error
You can handle the Application_Error to handle all unhandled exceptions.
Personally, I'd create an object that handles the error sending. Then, whenever you catch an exception, use this object. Things like web services will not trigger the Page_Error or Application_Error events.
-
May 4th, 2010, 07:56 AM
#4
Re: send error
Absolutely, the majority of your code should be written in such a way that error/exceptions are handled at the place that it occurs. i.e. correct use of Try/Catches. However, there are times that things happen that aren't anticipated, this is where Page/Application level error handling comes in. However, the point I am making is that you shouldn't rely on this.
Gary
-
May 4th, 2010, 11:12 AM
#5
Thread Starter
Frenzied Member
Re: send error
Hi,
I do use Try/Catches in my code, but there are some kind of errors that its not catching, it's for that reason that i wanted to use Page/Application level error handling.
-
May 5th, 2010, 01:31 AM
#6
Re: send error
Application_Error in global.asax.
http://msdn.microsoft.com/en-us/library/24395wz3.aspx
Send the email from there.
-
May 5th, 2010, 01:33 AM
#7
Re: send error
Originally Posted by met0555
Hi,
I do use Try/Catches in my code, but there are some kind of errors that its not catching, it's for that reason that i wanted to use Page/Application level error handling.
And that is the point that I was trying to make. I am not saying that it is wrong to use Application Error Handling, but rather, if and when an Application Error is caught, I would be doing some investigation as to what is causing that error and try and handle it elsewhere.
Gary
-
May 5th, 2010, 02:15 AM
#8
Re: send error
Have a look at Log4Net as well. There are many 'options' as to how the exceptions are processed (file, email, database, etc).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|