?
Solved

Generic error trapping

Posted on 2005-04-20
7
Medium Priority
?
274 Views
Last Modified: 2012-05-05
Hello,
Is there any way of providing an application-wide try-catch or does it have to be done on each web page seperately?
I currently provide a generic error message caught by using customErrors in web.config but it would be nice if the user didn't have to quit the application and re-start.

As an aside, i would also like to the webapp to send information to me via email if an error occurs - any useful functions/ thoughts on how to do this?

Thanks in advance,
mcg
0
Comment
Question by:mcgants
  • 5
  • 2
7 Comments
 
LVL 11

Accepted Solution

by:
Ramesh Srinivas earned 2000 total points
ID: 13822977
Yes there is.

In your Global.asax file insert the following into the Application_Error event:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
        Dim ErrorDescription As String = Server.GetLastError.ToString
       
        Dim MMsg As MailMessage = New MailMessage
        SmtpMail.SmtpServer = "intmeddc02"
        MMsg.To = emailadd
        MMsg.From = "iMediaAdmin@intmeds.com"
        MMsg.Subject = Subject
        MMsg.BodyFormat = MailFormat.Html
        Dim strBody = "The user: " & User.Identity.Name & " ran into an error @ " & Now & Chr(13) & "Error: " & ErrorDescription & "."
        MMsg.Body = strBody
        MMsg.Priority = MailPriority.High
        SmtpMail.Send(MMsg)
        MMsg = Nothing
End Sub

If you are using forms authentication then the line will retrieve username: User.Identity.Name

regards,

KS
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13822988
Just replace my settings with your own.
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13823012
Also, to make sure users do not see any asp.net error descriptions you can make your own html page which is displayed when an error occurs.

In your web.config file:

<customErrors defaultRedirect="error.htm" mode="RemoteOnly" />

error.htm is the page that will be displayed when an error occurs and it could say something like "Admin has been notified - try again later etc.

regards,

KS
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Author Comment

by:mcgants
ID: 13823639
thanks, that's great it works well, but before i finish, do you know if there is a resolution for the first part of my question:
"I currently provide a generic error message caught by using customErrors in web.config but it would be nice if the user didn't have to quit the application and re-start."
i'm thinking of a roll-back kind of thing where once an error has been generated, putting the user back to where they were. maybe i'm hoping for a bit too much, but the email message works a treat :)

cheers,
mcg
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13823700
Hmmm. You could put them back but they would still encounter the error if they attmepted to repeat the operation which caused it.

Perhaps you could put a link on your custom error page to take them back manually - or a redirect?

regards,

kS
0
 
LVL 6

Author Comment

by:mcgants
ID: 13823760
no worries, i was just trying to keep the app up and running through the error, but the code you've given me for the email was great. thanks!
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13823770
okay, no probs.

All the best,

kS
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question