Sending a custom error
stevescott
Posted on
Mar 08 2014
Okay, our cms has a page unauthorized event that fires if the user tries to access a page they shouldn't. How can I fire this into raygun, seeing as it's technically not an exception?
protected void OnPage_UnauthorizedAccess(Telerik.Sitefinity.Web.Events.IUnauthorizedPageAccessEvent unauthorizedEvent){
Logger.Writer.Write("Unauthorized page access:" + unauthorizedEvent.Page.Url); //want to change to raygun }
I would like them all "grouped" under the same heading so I dont want to put the URL in as the message...
John-Daniel Trask
Raygun
Posted on
Mar 13 2014
One quick way to ensure they are grouped together would be to create a type that inherits from Exception, e.g. UnauthorizedPageAccessException, and instantiate it inside that OnPage method, passing it to a RaygunClient instance. By code:
public class UnauthorizedPageAccessException : Exception { }
static RaygunClient _client = new RaygunClient('apikey');
protected void OnPage_UnauthorizedAccess(IUnauthorizedPageAccessEvent unauthedEvent) {
var e = new UnauthorizedPageAccessException() // populate message, or pass in "Unauthed page.." to constructor
var customData = new Dictionary<string, string>() { { "url", unauthorizedEvent.Page.Url } };
_client.Send(e, customData)
}
The Class Name is a key piece of data we use to perform grouping, so all exceptions that arrive will be placed in the same group (if they also have the same line numbers and file names in their stack trace). The message of an exception isn't taken into consideration when grouping, so you can add the Page.Url to the exception's Message and they will still be grouped together.