Click here to Skip to main content
15,893,161 members
Articles / Web Development / ASP.NET

OneTrueError and ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.83/5 (3 votes)
4 Aug 2014LGPL32 min read 11.9K   4  
OneTrueError is my new startup which also is a member of Microsoft BizSpark. This post is about the client library for ASP.NET (WebForms/MVC/WebAPI). It will catch and handle all uncaught exceptions automatically. They are also uploaded to our site for … Continue reading →

OneTrueError is my new startup which also is a member of Microsoft BizSpark. This post is about the client library for ASP.NET (WebForms/MVC/WebAPI). It will catch and handle all uncaught exceptions automatically. They are also uploaded to our site for analysis to enable us to suggest possible solutions

To get started you need to have an account at onetrueerror.com and download our nuget-package OneTrueError.AspNet. Once you’ve completed that you’ll only have to add these lines of code to your global.asax.

OneTrue.Configuration.Credentials("appKeyThatYouGot", 
                                  "sharedSecretThatYouGot");
OneTrue.Configuration.CatchAspNetExceptions();

Now we’ll be able to detect and handle all uncaught exceptions. Simply do something which would generate an exception, like visiting a page that do not exist. You should get our default error page which looks like this:

default-error-page

If you inspect the error page HTTP headers you’ll see that we use correct status codes:

404-error-code 402-error-code

We also honor the requested type. If the caller wants XML we do provide XML. Same goes for JSON.

return-xml return-json

Options

As you’ve might have seen, we collect a lot of context information to be able to provide you with possible error solutions. Some users do not like that and we can therefore enable you to allow them to choose if we can upload the report or not.

You simply change the initialization code:

OneTrue.Configuration.Credentials("appKeyThatYouGot", 
                                  "sharedSecretThatYouGot");
OneTrue.Configuration.AskForPermission = true;
OneTrue.Configuration.CatchAspNetExceptions();

That changes the error page to:

only_collect

You can also ask the user to provide details:

OneTrue.Configuration.AskForDetails = true;

only_details

To enable them to follow the progress of the error (and get notified when you’ve have completed the error) you change another flag:

OneTrue.Configuration.AskForEmail = true;

only_email

You can of course combine them:

combination

Customization

You do not have to use our error page. You can create your own ASPX or HTML page (those works for WebApi/MVC too). To activate it, use the following command:

OneTrue.Configuration.SetErrorPage("~/views/error.aspx");

Here is a sample that I’ve made:

< %@ Page Language="C#" AutoEventWireup="true" CodeBehind="Error.aspx.cs" Inherits="TestWebApp.Views.WebForm1" %>
< %@ Import Namespace="OneTrueError.Reporting" %>
< !DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>OneSite - Deadly error</title>
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Butcherman"/>
</head>
<body style="background: #000; color: red;font-family: Butcherman; text-align: center; font-size: 1.2em">
    <h1>We are all doomed</h1>
    <img runat="server" src="~/Images/doomed.jpg"/>
    <form id="form1" runat="server">
    <div>
    < %: ((Exception)Context.Items["Exception"]).Message  %>
    </div>
    </form>
</body>
</html>

Result:

custom-error-page

You can also use a callback to provide different error pages for different errors:

public class WebApiApplication : System.Web.HttpApplication
{
	protected void Application_Start()
	{
		OneTrue.Configuration.Credentials("appKeyThatYouGot", "sharedSecretThatYouGot");
		OneTrue.Configuration.SetErrorPage(ErrorPageGenerator);
		OneTrue.Configuration.CatchAspNetExceptions();

		AreaRegistration.RegisterAllAreas();
		WebApiConfig.Register(GlobalConfiguration.Configuration);
		FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
		RouteConfig.RegisterRoutes(RouteTable.Routes);
		BundleConfig.RegisterBundles(BundleTable.Bundles);
	}

	private string ErrorPageGenerator(HttpErrorReporterContext context)
	{
		var errorPage = context.HttpContext.Response.StatusCode == 404
			? "~/Views/404.aspx"
			: "~/Views/Error.html";

		// class in our library
		return PageBuilder.Build(errorPage, context);
	}
}

Context information

At our website you can see all information about the HTTP request, response, sessions and cookies.

Image 11

Dashboard

The collected information (exceptions etc) are presented in our dashboard:

Image 12

This article was originally posted at http://blog.gauffin.org/2014/01/onetrueerror-and-asp-net

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder 1TCompany AB
Sweden Sweden

Comments and Discussions

 
-- There are no messages in this forum --