setting the web.config file

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

setting the web.config file

 
0
  #1
Feb 1st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: setting the web.config file

 
0
  #2
Feb 1st, 2007
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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: setting the web.config file

 
0
  #3
Feb 2nd, 2007
Thanks
How can I test it? in the localhost?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: setting the web.config file

 
0
  #4
Feb 2nd, 2007
thanks for the reply

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

How is this?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

Re: setting the web.config file

 
0
  #5
Feb 2nd, 2007
just add a global.asax file, right click the web project in solution explorer, click add
then select global.asax from the available files
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: setting the web.config file

 
0
  #6
Feb 2nd, 2007
I got it Sedgey
thanks for your prompt reply

Can you please tel me, how can I test the application from local host?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: setting the web.config file

 
0
  #7
Feb 2nd, 2007
do something that you now will cause an unhandled excpetion on one of your pages
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC