Using Ajax.net to get javascript errors to asp.net
Since AJAX is the latest gimmick on the web, and Ajax.net is opensource now, I started thinking of things that can be done with it, so here is #1 of Colin's ajax gimmicks:
Are you tired of your dumb-ass users sending you screenshots or trying to explain what error they got? With this you can record the error server side (assuming that the ajax.net part is working
)
using System;
using Ajax;
using System.Web.UI;
namespace AspAjaxControls
{
public class ErrorHandler:Control,INamingContainer
{
public ErrorHandler()
{
Ajax.Utility.RegisterTypeForAjax(typeof(ErrorHandlerMethods));
}
internal class ErrorHandlerMethods
{
[AjaxMethod()]
public void ReportError(string desc, string page, string line)
{
System.Diagnostics.Debug.WriteLine(String.Format("Error : {0} on page {1} at line {2}", desc,page,line),"javascript error");
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
if (Page != null)
{
if (!Page.IsStartupScriptRegistered("__AjaxErrorHandler"))
Page.RegisterStartupScript("__AjaxErrorHandler","
");
}
}
}
}
Just add the above class to your project with the Ajax.net reference, insert into a asp.net page using
<cc1:ErrorHandler id=errorhandler1 runat="server"></cc1:ErrorHandler>
and you have server side logging of javascript errors.
powered by IMHO 1.2