PDA

Click to See Complete Forum and Search --> : [Resolved] redirect and mail on error


RTT2001
Apr 4th, 2005, 04:29 AM
i want to make it so, that when an error accurs, the people get redirected to an error page, and that the error is being send to me.



in the web.config file i added:
<customErrors defaultRedirect="error.htm" mode="RemoteOnly" />



in the global.asax i added:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Fires when an error occurs
sendmail(Server.GetLastError)
End Sub



with the function:

Dim mail As New MailMessage
mail.To = """name"" <email@email.com>"
mail.From = """ Error "" <email@email.com>"

mail.BodyFormat = MailFormat.Html
mail.Priority = MailPriority.High
mail.Subject = "Error Report - " & Date.Now.ToString
mail.Body = ""
mail.Body += "<u><b>ErrorMessage:</b></u><br>"
mail.Body += Ex.Message.ToString & "<br><br>"
mail.Body += "<b>exception: </b>" & ex.ToString
mail.Body += "<br><br><b>Reported on: </b>" & Date.Now.ToString
SmtpMail.SmtpServer = "BEXXGHE01IS0020"
SmtpMail.Send(mail)



it works, i get an email when an error accurs and the user is redirected, but i always get something like this:



ErrorMessage:
Exception of type System.Web.HttpUnhandledException was thrown.

exception: System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.IndexOutOfRangeException: There is no row at position 4. at System.Data.DataRowCollection.get_Item(Int32 index) at ResourcesManagement1.containersOverview.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\ResourcesManagement1\Asp\containersOverview.aspx.vb:line 68 at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain() --- End of inner exception stack trace --- at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain() at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Reported on: 04/04/2005 11:05:57



the error is always of the type System.Web.HttpUnhandledException, while i know the error should be of other types. anybody who knows what causes this and how to solve it?

mendhak
Apr 4th, 2005, 04:39 AM
You'll have to do more than Server.GetLastError(). For one, use it's GetBaseException method/property.

Take a look here for some ideas:

http://support.microsoft.com/default.aspx?scid=kb;en-us;306355

You'll notice that they're working with GetBaseException, passing it to an object and then using its properties to create a proper message that you can understand too when you receive your email.

If you're going to simply use GetLastError, then you can always expect an exception of type HTTPUnhandledException.

RTT2001
Apr 4th, 2005, 04:55 AM
thxs a lot, it solved my problem

mendhak
Apr 4th, 2005, 05:04 AM
Great. :) Add [Resolved] to the thread title and have a beer.