Cunning Plan

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
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...
 
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.
 
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....
 
sample code for storing last rendered html
Code:
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.:
Code:
<%@ 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>
 
HJB417 said:
sample code for storing last rendered html
Code:
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.
 
samsmithnz said:
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.

impossible, 'Render' happens after 'Load'
 
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...
 
Back
Top