User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,454 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,764 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3138 | Replies: 6
Reply
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

setting the web.config file

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: setting the web.config file

  #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

		protected void Application_Error(Object src, EventArgs e ){
			string emAddr = "developer@yoursite.com"
			string trc,message = "Application Error";
				Exception objError = Server.GetLastError();
				if(objError.InnerException != null)
					objError = objError.InnerException;
				
				HttpContext.Current.Application.Add("lastException",objError);
				Server.ClearError();
				trc = objError.StackTrace.Replace(" at ", "<li>");
				trc = trc.Replace(" in ", "<br>&nbsp;&nbsp;&nbsp;&nbsp;");

				message = "<table>"+
					"<tr><td colspan=2><b>Application Error</b></td></tr>"+
					"<tr><td width=80 valign=top>Source:</td><td>"+ objError.Source + "</td></tr>"+
					"<tr><td valign=top>Error:</td><td>"+ objError.Message +"</td></tr>"+
					"</table><hr align=center width=80%><table>"+
					"<tr><td>Stack Trace:</td></tr>"+
					"<tr><td>"+ trc +"</td></tr></table>";
					
				SendEmail(emAddr, "Application Error", message,true);

			Server.Transfer("YourErrorPage.aspx"); 
		}

		public static void SendEmail(string To, string Subject, string Body, bool HTML) {

			System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
			mail.To = To;
			mail.From = "whoever@yoursite.com";
			mail.Subject = Subject;
			mail.Body=Body;
			mail.BodyFormat = (HTML?System.Web.Mail.MailFormat.Html:System.Web.Mail.MailFormat.Text);

			System.Web.Mail.SmtpMail.SmtpServer = "yourmailserver";
			System.Web.Mail.SmtpMail.Send(mail);
		}
Reply With Quote  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: setting the web.config file

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

Re: setting the web.config file

  #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  
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation: sedgey is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
sedgey sedgey is offline Offline
Junior Poster in Training

Re: setting the web.config file

  #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
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
Reply With Quote  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: setting the web.config file

  #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  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: setting the web.config file

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

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC