Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Posted
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.
Posted

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....

Posted

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>

Posted
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.

Posted
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'

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...