I have added the ability for us to log errors to our database for all HTTPExceptions. Once this was pushed live we logged about 10,000 in the span of around 15 minutes. I have to assume these errors were happening all the time, but since they were not critical errors the user didn't notice anything.
Here is the code in my Global.asax
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception is HttpException)
{
var httpException = exception as HttpException;
if (httpException.GetHttpCode() == 404)
{
// Page not found error
Response.StatusCode = 404;
using (MyEntities db = new MyEntities())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = httpException.GetHttpCode().ToString();
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
else if (httpException.GetHttpCode() == 500)
{
// Server Error
Response.StatusCode = 500;
using (MyEntities db = new MyEntities ())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = httpException.GetHttpCode().ToString();
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
else
{
// All Other Errors
Response.StatusCode = 500;
using (MyEntities db = new MyEntities ())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = "999";
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
}
Out of the 10,000 errors we have logged only 50 of them were unique.
Here are examples of some of them
type Message
999 A potentially dangerous Request.Path value was detected from the client (:).
999 A potentially dangerous Request.Path value was detected from the client (>).
404 The controller for path '/images/favicon.ico' was not found or does not implement IController.
404 The controller for path '/Scripts/jquery-1.4.2.min.js' was not found or does not implement IController.
404 The controller for path '/Scripts/jquery-ui-1.8.5.custom.min.js' was not found or does not implement IController.
Now these seem like pretty silly errors. And from a user stand point this does not throw them to our custom 404 error page. So I am guessing they hit this error and are later redirected so they never see or notice they hit an error unless something is wrong with the code.
Anyone able to point me in the right direction to fix these if they are legitimate errors?
The last three 404 errors don't even make sense to me because they are not controllers and should not be treated like controllers ever.