samsmithnz Posted April 30, 2005 Posted April 30, 2005 I had a cunning thought today. In my current ASP.NET project (A fairly simple application used by 3000 users), I currently receive an email everytime there is an unexpected exception. I was thinking today wouldn't it be cool if the email included more information, like the current HTML for the screen the user is on... So I could see the error, and exactly what they were doing. Is there a way to currently do this? Any thoughts anyone? I thought this might make support a little easier... Quote Thanks Sam http://www.samsmith.co.nz
HJB417 Posted April 30, 2005 Posted April 30, 2005 well, addressing the current html issue, you usually can't see the 'current' html because the error is thrown before it's completely rendered as html and sent to the client. If you really want to get the HTML, maybe you can email yourself the 'last successfully rendered HTML', basically, override the OnRender method so and store the HTML in a session object. ASP.NET usually relies on user created IL code, make sure you have efficient error logging of your .NET code because it'll limit the scope of the problem. Quote
samsmithnz Posted April 30, 2005 Author Posted April 30, 2005 You're right, the last successful rendering of HTML. Most of my errors happen after a page has loaded, the user enters data and then submits the page to the server. How would I capture this last rendored HTML? If only there a me.page.html or something like that... ;) I'm just trying to see if theres anything useful that all web devs kind benefit from.... Quote Thanks Sam http://www.samsmith.co.nz
HJB417 Posted April 30, 2005 Posted April 30, 2005 sample code for storing last rendered html public class Class2 : System.Web.UI.Page { protected override void Render(System.Web.UI.HtmlTextWriter writer) { using(System.IO.StringWriter sw = new System.IO.StringWriter()) using(System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw)) { base.Render(tw); string html = sw.ToString(); writer.Write(html); Session["LastRenderedHtml"] = html; } } } Also, I have code to perform exception logging in my global.asax file. e.x.: <%@ Application %> <script runat="server"> void Application_Error(object sender, EventArgs e) { Exception error = Server.GetLastError(); if(error != null) { string msg = "an error occurred and stuff\r\n" + error; BlackBoxCode.SendEmail(msg); } } </script> Quote
samsmithnz Posted May 2, 2005 Author Posted May 2, 2005 sample code for storing last rendered html public class Class2 : System.Web.UI.Page { protected override void Render(System.Web.UI.HtmlTextWriter writer) { using(System.IO.StringWriter sw = new System.IO.StringWriter()) using(System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw)) { base.Render(tw); string html = sw.ToString(); writer.Write(html); Session["LastRenderedHtml"] = html; } } } This is good stuff, but it always shows the HTML before I've loaded it with data from my page_load event. Any ideas on how to get this too? Still experimenting. Quote Thanks Sam http://www.samsmith.co.nz
HJB417 Posted May 2, 2005 Posted May 2, 2005 This is good stuff' date=' but it always shows the HTML before I've loaded it with data from my page_load event. Any ideas on how to get this too? Still experimenting.[/quote'] impossible, 'Render' happens after 'Load' Quote
samsmithnz Posted May 3, 2005 Author Posted May 3, 2005 Isn't this still ok? I load my web controls with page_load, and I'm expecting to see this in the rendor, as it happens AFTER page_load... Quote Thanks Sam http://www.samsmith.co.nz
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.