Try our conversational search powered by Generative AI!

Customized error handling in global


We've recently noticed on our live site that we get a lot of errors in the log related to "The controller for path '/something/else' was not found or does not implement IController". Many times this seems to be hacker attempts, trying to forecfully access wordpress admin urls or other similar cgi-related urls. Thing is, whenever this happens, an error is caught in Episerver.Global which is logged as an Error. If you have SCOM monitoring these kinds of errors will eventually flood your system.

What I would like to do is to catch this very error and adjust it to be a warning. How can I intercept an error in my custom global implementation before Episerver gets hold of it?

Mar 03, 2015 22:17

It seems my custom Application_Error is called before Episerver's Global_Error, so I thought I would try and clear the error to prevent Global_Error from catching it. I tried all combinations of ClearError but with no success. Somehow Global_Error still found it and logged it ("1.2.5 Unhandled exception in ASP.NET"). Finally I tried to forcefully set HttpContext.Current = null when my condition was true, and this seemed to stop Episerver from catching my error. But it does not really seem like the right thing to do :-/

Mar 03, 2015 23:20

In fact i have the same problem, can someone tell me or there is a fix for this? The main problem is that due to this problem we also get a lot of false-positives in our New Relic monitoring because the level of logging for this is: Error.

Dec 21, 2015 16:11


When you call ClearError() what you get back from HttpContext.AllErrors?

At the moment the only way to "shut up" EPiServer logging on Error severity for these cases would be to either get HttpContext.Error property to return null or set HttpContext to null (as you already did it).

Dec 30, 2015 22:33

For anyone interested, this is the code that we use to intercept 404:s and turn them into warnings

protected void Application_Error(Object sender, EventArgs e)
	var ex = Server.GetLastError().GetBaseException();

	if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
		// This is the only working approach we've found to prevent Episerver from grabbing the error in Global_Error and logging it.
		HttpContext.Current = null;
		Logger.WarnFormat("Requested url '{0}' not found", Request.Url);
		Response.StatusCode = 404;
Jan 13, 2016 8:46


What type is "Logger" in your example?


Apr 01, 2016 15:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.