I've written something similiar. This also has the capability to send emails and includes the entire stack trace (with line numbers). I have the source code, if you wanna download and look at it... http://joel.net/code/global_errors.aspx Joel Thoms DiscountASP.NET http://www.DiscountASP.NET
Thanks a lot. Loaded up the code and tried it out. However I get the same problem that I was having. No line numbers! Below is email I got back from a test. However the default error page displays everything just dandy! (I have pasted in the generated HTML for your reference) Cheers Mitch An error occurred at https://www.catprint.bz/admin/default.aspx Input string was not in a correct format. Error Information Name Value Source Microsoft.VisualBasic Exception Type System.FormatException Message Input string was not in a correct format. StackTrace at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) TargetSite Double ParseDouble(System.String, System.Globalization.NumberFormatInfo) Cookies Collection Name Value whoson 723-1155755145731 machine-id 70.101.33.244%3A1155700952478 ASP.NET_SessionId nj25bv55gv2xmi55uvc4yuew gblUserID 2 .ASPXAUTH 44F961496CA555ED24762DEA8866076CCD061051F19436E824D04BBA9C66857F7FE708C1 76DA1480D9C845FD7BB59A3189E47979F29CFB59639657ABA19C72F7 Session Variables Name Value gblCatalogID 1 gblUserID 0 FurtherestStep 0 objOrderHeader ISWebCat.OrderHeader thePrices CatPrint.Price JT JT ShippingMethods ShippingMethods JTC JTC IT IT CreditCardType CreditCardType Username ErrorMan Fullname log in this way to cause an error Server Variables Name Value ALL_HTTP HTTP_CONNECTION:keep-alive HTTP_KEEP_ALIVE:300 HTTP_ACCEPT:text/xml,application/xml,application/xhtml+xml,text/html;q=0 .9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING:gzip,deflate HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_COOKIE:whoson=723-1155755145731; machine-id=70.101.33.244%3A1155700952478; ASP.NET_SessionId=nj25bv55gv2xmi55uvc4yuew; gblUserID=2; .ASPXAUTH=44F961496CA555ED24762DEA8866076CCD061051F19436E824D04BBA9C6685 7F7FE708C176DA1480D9C845FD7BB59A3189E47979F29CFB59639657ABA19C72F7 HTTP_HOST:www.catprint.bz HTTP_REFERER:https://www.catprint.bz/admin/Login.aspx?ReturnURL=default. aspx HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 ALL_RAW Connection: keep-alive Keep-Alive: 300 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai n;q=0.8,image/png,*/*;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Accept-Encoding: gzip,deflate Accept-Language: en-us,en;q=0.5 Cookie: whoson=723-1155755145731; machine-id=70.101.33.244%3A1155700952478; ASP.NET_SessionId=nj25bv55gv2xmi55uvc4yuew; gblUserID=2; .ASPXAUTH=44F961496CA555ED24762DEA8866076CCD061051F19436E824D04BBA9C6685 7F7FE708C176DA1480D9C845FD7BB59A3189E47979F29CFB59639657ABA19C72F7 Host: www.catprint.bz Referer: https://www.catprint.bz/admin/Login.aspx?ReturnURL=default.aspx User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 APPL_MD_PATH /LM/w3svc/206599/root APPL_PHYSICAL_PATH E:\web\print2mecom\htdocs\ AUTH_TYPE AUTH_USER AUTH_PASSWORD LOGON_USER REMOTE_USER CERT_COOKIE CERT_FLAGS CERT_ISSUER CERT_KEYSIZE 128 CERT_SECRETKEYSIZE 1024 CERT_SERIALNUMBER CERT_SERVER_ISSUER O=VeriSign Trust Network, OU='VeriSign, Inc.', OU=VeriSign International Server CA - Class 3, OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign CERT_SERVER_SUBJECT C=US, S=New York, L=Rochester, O=CatPrint, OU=Web, OU=Terms of use at www.verisign.com/rpa (c)05, CN=www.catprint.bz CERT_SUBJECT CONTENT_LENGTH 0 CONTENT_TYPE GATEWAY_INTERFACE CGI/1.1 HTTPS on HTTPS_KEYSIZE 128 HTTPS_SECRETKEYSIZE 1024 HTTPS_SERVER_ISSUER O=VeriSign Trust Network, OU='VeriSign, Inc.', OU=VeriSign International Server CA - Class 3, OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign HTTPS_SERVER_SUBJECT C=US, S=New York, L=Rochester, O=CatPrint, OU=Web, OU=Terms of use at www.verisign.com/rpa (c)05, CN=www.catprint.bz INSTANCE_ID 206599 INSTANCE_META_PATH /LM/W3SVC/206599 LOCAL_ADDR 64.209.134.99 PATH_INFO /admin/default.aspx PATH_TRANSLATED E:\web\print2mecom\htdocs\admin\default.aspx QUERY_STRING REMOTE_ADDR 70.101.33.244 REMOTE_HOST 70.101.33.244 REMOTE_PORT 3304 REQUEST_METHOD GET SCRIPT_NAME /admin/default.aspx SERVER_NAME www.catprint.bz SERVER_PORT 443 SERVER_PORT_SECURE 1 SERVER_PROTOCOL HTTP/1.1 SERVER_SOFTWARE Microsoft-IIS/6.0 URL /admin/default.aspx HTTP_CONNECTION keep-alive HTTP_KEEP_ALIVE 300 HTTP_ACCEPT text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai n;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING gzip,deflate HTTP_ACCEPT_LANGUAGE en-us,en;q=0.5 HTTP_COOKIE whoson=723-1155755145731; machine-id=70.101.33.244%3A1155700952478; ASP.NET_SessionId=nj25bv55gv2xmi55uvc4yuew; gblUserID=2; .ASPXAUTH=44F961496CA555ED24762DEA8866076CCD061051F19436E824D04BBA9C6685 7F7FE708C176DA1480D9C845FD7BB59A3189E47979F29CFB59639657ABA19C72F7 HTTP_HOST www.catprint.bz HTTP_REFERER https://www.catprint.bz/admin/Login.aspx?ReturnURL=default.aspx HTTP_USER_AGENT Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 ----------------Default Error Handler------------------------------------------------------------------------- <html> <head> <title>Input string was not in a correct format.</title> <style> body {font-family:'Verdana';font-weight:normal;font-size: .7em;color:black;} p {font-family:'Verdana';font-weight:normal;color:black;margin-top: -5px} b {font-family:'Verdana';font-weight:bold;color:black;margin-top: -5px} H1 { font-family:'Verdana';font-weight:normal;font-size:18pt;color:red } H2 { font-family:'Verdana';font-weight:normal;font-size:14pt;color:maroon } pre {font-family:'Lucida Console';font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } </style> </head> <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> <h2> <i>Input string was not in a correct format.</i> </h2></span> <font face='Arial, Helvetica, Geneva, SunSans-Regular, sans-serif '> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: </b>System.FormatException: Input string was not in a correct format. Source Error:</b> <table width=100% bgcolor='#ffffcc'> <tr> <td> <code><pre> Line 24: If Trim(Session('Username')) = '' Then Response.Redirect('Login.aspx?ReturnURL=default.aspx') 'FormsAuthentication.RedirectToLoginPage('admin=1') '(Response.Redirect('Login.aspx')) Line 25: If Trim(Session('Username')) = 'ErrorMan' Then <font color=red>Line 26: Dim xxx As Integer = 'abc' </font>Line 27: End If Line 28: End Sub</pre></code> </td> </tr> </table> Source File: </b> E:\web\print2mecom\htdocs\admin\default.aspx.vb Line: </b> 26 Stack Trace:</b> <table width=100% bgcolor='#ffffcc'> <tr> <td> <code><pre> [FormatException: Input string was not in a correct format.] Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +211 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +84 [InvalidCastException: Conversion from string 'abc' to type 'Integer' is not valid.] Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +238 CatPrintAdmin._default.Page_Load(Object sender, EventArgs e) in E:\web\print2mecom\htdocs\admin\default.aspx.vb:26 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061 </pre></code> </td> </tr> </table> <hr width=100% size=1 color=silver> Version Information:</b>Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 </font> </body> </html> <!-- [FormatException]: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) [InvalidCastException]: Conversion from string 'abc' to type 'Integer' is not valid. at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at CatPrintAdmin._default.Page_Load(Object sender, EventArgs e) in E:\web\print2mecom\htdocs\admin\default.aspx.vb:line 26 at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown. at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.admin_default_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) [HttpException]: Unhandled HttpException while processing NeatUpload child request at Brettle.Web.NeatUpload.UploadHttpModule.Application_BeginRequest(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) --><!-- This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode='Off'/>. Consider using <customErrors mode='On'/> or <customErrors mode='RemoteOnly'/> in production environments.-->
I have written a custom exception handler that emails me any exceptions. Seems to work fine, except I do not get any line number information in the stack trace, and the error message doe not have as much detail as the default exception page. Note that debug='true' in the web.config, and that the default exception page that comes up is fine, so the information is all there. Is there some setting or something I need to get the line numbers?
Joel, I have looked a bit closer at this 'test' and I notice that the only place I am missing line numbers is on the actual Source line. How can we get the line number of the actual source error file like the default error handler has? Cheers Mitch
Is your DLL compiled with debug mode? Is the pdb file in the bin directory? Bruce DiscountASP.NET www.DiscountASP.NET
I have to claim ignorance. I don't know what a .PDB file is, how to get one etc. Also I am not sure why this would help. I see all the info I need in the default error handler. Why can't I get ahold of this info somehow and just mail it to myself? Thanks in advance!
Is you application compiled as code behind (or precompiled)? The pdb file includes all the debug information including line number. If your application is not precompiled, and you do not include the PDB file, you will not get the line information in the error trapping. Bruce DiscountASP.NET www.DiscountASP.NET
Joel / Bruce On closer inspection of some other errors, I see that in the stack trace, I DO get line numbers and files. NOTE I am getting this simply by having debug='true' in the config file. No need for .pdb files etc. (or maybe they are generated for me automatically?) GREAT! However I don't get the line number or source of the actual line that the error happens on. This is okay if the source line is somewhere in the stack trace (i.e. I can just look down the stack trace until I find a line in my code, and that's the offending line.) However some errors don't seem to include my code in the stack trace. For example as a test I included the following line in my code: dim dummy as integer = 'foobar!' The error stack for this line looks like this: Source Microsoft.VisualBasic Exception Type System.FormatException Message Input string was not in a correct format. StackTrace at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) TargetSite Double ParseDouble(System.String, System.Globalization.NumberFormatInfo)
What you posted is a compiler error, which will prevent the page from ever being compiled in the first place. It'd be the same as posting "asdlkfjlsadj" on a blank line and expecting the page to run. I've seen this behavior before with compiler errors, there's nothing you can do about these. To force an error you can do something like this.. Dim X As Integer = 0 X =123 / x Or Throw new Exception("oops i did it again.") Joel Thoms DiscountASP.NET http://www.DiscountASP.NET
Joel, Thank you very much, and thanks for you nice piece of code (your HTMLError package.) In particular I like the session variable dump. Very useful! The compiler must be incremental, as I had put the bogus error line containing dim x = 'abc' in an IF statement and the file runs fine as long as it doesn't execute the bogus line. Only when it executes that line do I get the error. Any way I tried the divide by a variable equal to zero as you suggest, and I do get a nice report. Cheers and thanks! Mitch
Hi, I was having the same problem and was really pleased to find this posting. However having read through it I am none the wiser. All I want logged to my error db is the page and the line that caused the exception. This works locally when devloping but as soon as I test it on here I get the same problem, no file name and no line number Locally the stack trace appears as; at test.btnError_Click(Object sender, EventArgs e) in E:\Gwsfhsdev\test.aspx.vb:line 15 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at ...... As soon as I try the error when hosted, the info I need vanishes; at test.btnError_Click(Object sender, EventArgs e) atSystem.Web.UI.WebControls.Button.OnClick(EventArgs e) at ...... Surely I don't need to keep debug=true in production to get this info? I keep reading what a bad idea this is. I'd be grateful for any more tips. Thanks PS; The error is generated by a button which executes this; Dim intError1 As Integer = 12 Dim intError2 As Integer = 0 Dim intError3 As Integer intError3 = intError1 / intError2
what and how do you upload a .pdb file... sorry for my ignorance! Is there a pointer to a site that could give me the basics on this whole area?
Oh, I think you're using .net 2.0 right? So unless you're specifically compiling the project a dll/pdb wont be created. You'll need to set debug=true to get this info. Joel Thoms DiscountASP.NET http://www.DiscountASP.NET
Joel, I am probably confusing things here. Somebody else was actually asking the question previously about debug='false'. I don't know if he/she is using 2.0 or 1.0. I am using 2.0 and compile with debug='true' and everything is working good. I have tracked down several problems with the software you pointed me too. I am curious however what to do when I reach the point that I want to turn debugging off (or do I ever want to do this?) I do is there anyway to get the debug information? Mitch
If you turn off debugging, you cannot get this debug information. What I've done, is I leave debugging on andI use my Global Error Handler in my global.asax file and also redirect to a "sorry.aspx" page. This prevents the error message from being sent to the user, and emails it to myself for review. I leave debugging on so I can see the line numbers. Joel Thoms DiscountASP.NET http://www.DiscountASP.NET
That's also what I am doing now. Is there any penalty performance wise to leaving debugging on? Thanks by the way for answering all these new-bie questions! Mitch
I'm sure there is, but it appears to be insignificant. I've seen high traffic sites with debugging on and haven't noticed much of a difference. Joel Thoms DiscountASP.NET http://www.DiscountASP.NET
This is a good article that you want to read about this very topic http://weblogs.asp.net/scottgu/archive/2006/04/11/Don_1920_t-run-production-ASP.NET-Applications-with-debug_3D001D20_true_1D20_-enabled.aspx Bruce DiscountASP.NET www.DiscountASP.NET