943,985 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 5633
  • ASP.NET RSS
Feb 1st, 2007
0

setting the web.config file

Expand Post »
http://www.aspmessageboard.com/images/printer.gifhi all

I am trying to implement exception handling in my application, where I come accross some questions

I have set the customerror mode to renote only, and defaultredirect to a asp.net page.

1) do I have to comment that out, till i release the project?
2) for local host what will happen, if i set some page for the default error and error event?

For processing the unhandled exceptions, like sending mail to developer, what all I have to be careful

I am realy afraid of chanign something in web config

can anyone please clear my questions

thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 1st, 2007
0

Re: setting the web.config file

let me give you some sample code. You don't need to change web.config at all

you want to put this code in your global.asax code behind. This is for C#.Net but you should be able to convert it to VB.Net if thats what you are using

ASP.NET Syntax (Toggle Plain Text)
  1. protected void Application_Error(Object src, EventArgs e ){
  2. string emAddr = "developer@yoursite.com"
  3. string trc,message = "Application Error";
  4. Exception objError = Server.GetLastError();
  5. if(objError.InnerException != null)
  6. objError = objError.InnerException;
  7.  
  8. HttpContext.Current.Application.Add("lastException",objError);
  9. Server.ClearError();
  10. trc = objError.StackTrace.Replace(" at ", "<li>");
  11. trc = trc.Replace(" in ", "<br>&nbsp;&nbsp;&nbsp;&nbsp;");
  12.  
  13. message = "<table>"+
  14. "<tr><td colspan=2><b>Application Error</b></td></tr>"+
  15. "<tr><td width=80 valign=top>Source:</td><td>"+ objError.Source + "</td></tr>"+
  16. "<tr><td valign=top>Error:</td><td>"+ objError.Message +"</td></tr>"+
  17. "</table><hr align=center width=80%><table>"+
  18. "<tr><td>Stack Trace:</td></tr>"+
  19. "<tr><td>"+ trc +"</td></tr></table>";
  20.  
  21. SendEmail(emAddr, "Application Error", message,true);
  22.  
  23. Server.Transfer("YourErrorPage.aspx");
  24. }
  25.  
  26. public static void SendEmail(string To, string Subject, string Body, bool HTML) {
  27.  
  28. System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
  29. mail.To = To;
  30. mail.From = "whoever@yoursite.com";
  31. mail.Subject = Subject;
  32. mail.Body=Body;
  33. mail.BodyFormat = (HTML?System.Web.Mail.MailFormat.Html:System.Web.Mail.MailFormat.Text);
  34.  
  35. System.Web.Mail.SmtpMail.SmtpServer = "yourmailserver";
  36. System.Web.Mail.SmtpMail.Send(mail);
  37. }
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Feb 2nd, 2007
0

Re: setting the web.config file

Thanks
How can I test it? in the localhost?
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 2nd, 2007
0

Re: setting the web.config file

thanks for the reply

But I tried to add the code in gloabl.asax, but it is missing in my application.

How is this?
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 2nd, 2007
0

Re: setting the web.config file

just add a global.asax file, right click the web project in solution explorer, click add
then select global.asax from the available files
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
Feb 2nd, 2007
0

Re: setting the web.config file

I got it Sedgey
thanks for your prompt reply

Can you please tel me, how can I test the application from local host?
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 2nd, 2007
0

Re: setting the web.config file

do something that you now will cause an unhandled excpetion on one of your pages
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: save a picture in SQL
Next Thread in ASP.NET Forum Timeline: Radiobuttonlist setting attributes for radiobuttons





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC