Error Emails


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Error Emails

  1. #1
    Join Date
    Oct 2004
    Posts
    63

    Question Error Emails

    I have a question. I am doing some web development using c# and I have my app set up so that when a user gets an error, they get a very user friendly error page, that looks more professional than the basic error page. Problem being, the user can't always describe to you what the problem is, which I'm sure you've all come across before.

    My question is, on my error page I have a bunch of variables that store the error and stack trace and all of that other good stuff. Is there any way to have that emailed to me automatically everytime a user gets the errorpage?

    Thanks in advance.

  2. #2
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    The types of varialbes you can grab is very limited. Like you will lose all of your page and form variables if the page errors out in the middle (I have been looking for a way to get around that but haven't come across anything). (sorry i can only provide u code in VB)

    If you turn your trace on, and look at that trace, you can pretty much get anything (I think) except form collection. Just create:

    Sub Application_Error(Sender As Object, E As EventArgs)



    in your global.asax and within that sub you will create your email like you normally would in any ASP.Net page. In the body you will print out the InnerException and Server type variables.
    new to programming but getting ther

  3. #3
    Join Date
    Oct 2004
    Posts
    63
    And this will automatically shoot an email to me without any user interaction?

  4. #4
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    Yes it will automatically use your email client sitting on ur server and create an email every time there is an error whether you have a default/custom error page or not.
    new to programming but getting ther

  5. #5
    Join Date
    Oct 2004
    Posts
    63
    I've been working on this for quite some time now and I can't get the email to work. Do you have any sample code or any sites that give a good explanation of the process. I've been struggling with this for some time now and decided I just don't get it. Thanks for the help.

  6. #6
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    here is a small sample:
    Sub Application_Error
    Dim mm as New MailMessage
    Dim str as string = Server.GetLastError().GetBaseException()
    str &= " on page " & Request.Path & " from page " & Server.UrlDecode(request.servervariables("HTTP_REFERER"))

    mm.From = "error@domain.com"
    mm.To = "Webmastser@domain.com"
    mm.Subject = "An error"
    mm.Body = str

    smtp.send(mm)

    End Sub

    All of this code will go in your global.asax file




    another one by someones else
    http://www.123aspx.com/redir.aspx?res=31020
    this uses Global Exception class. You can use the inner exception class as well (search for it on MSDN). Up here, you can also add stuff like Request.ServerPath where the error occured and http_referer for where the person came from.

    The only thing you do up here is instead of writing the error in ur log file, you will email it to yourself.
    Last edited by kashif_82; 02-11-2005 at 04:20 PM.
    new to programming but getting ther

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center