[IMG]http://www.aspmessageboard.com/images/printer.gif[/IMG]hi 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

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);
		}

thanks for the reply

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

How is this?

just add a global.asax file, right click the web project in solution explorer, click add
then select global.asax from the available files

I got it Sedgey
thanks for your prompt reply

Can you please tel me, how can I test the application from local host?

do something that you now will cause an unhandled excpetion on one of your pages

This article has been dead for over six months. Start a new discussion instead.