Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Automatic MvcExceptionFilter injeciton triggers an Exception if Error View is not found #921

Closed
rzontar opened this issue May 23, 2018 · 1 comment
Assignees
Labels

Comments

@rzontar
Copy link

rzontar commented May 23, 2018

Since AI 2.6 the MvcExceptionFilter is automatically injected into the global filters. This broke some of our Applications, because we don't rely on MVC ExceptionFilters to handle our Exceptions.

I identified the cause to be the base.OnException call inside the Filter, which executes the default ExceptionHandling code.
https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/33696c0d09a3c6e93a690198a09bd49d84a63c58/Src/Web/Web.Shared.Net/Implementation/ExceptionHandlersInjector.cs#L100
I believe this is obtrusive and could be easily avoided by not handling the exception in the base class, but rather only logging it.

As an alternative, is there an opt-out option for not automatically injecting the Filter?
Our current workaround is by registering our own ExceptionFilter and rethrowing the Exception.

Repro Steps

  1. Create empty ASP.NET MVC 5 Application
  2. Add Microsoft.ApplicationInsights.Web Package
  3. Turn customErrors mode="On"
  4. Create a HomeController and throw an Exception in Index()
  5. View Exception details in EventViewer or other Logging Framework

Actual Behavior

    Exception type: InvalidOperationException 
    Exception message: The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Error.aspx
~/Views/Home/Error.ascx
~/Views/Shared/Error.aspx
~/Views/Shared/Error.ascx
~/Views/Home/Error.cshtml
~/Views/Home/Error.vbhtml
~/Views/Shared/Error.cshtml
~/Views/Shared/Error.vbhtml

Expected Behavior

The actually thrown exception should be logged.

Version Info

SDK Version : 2.6.1
.NET Version : 4.7.1
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) :
OS : SDK
Hosting Info (IIS/Azure WebApps/ etc) : IIS

@lmolkova
Copy link
Member

lmolkova commented May 23, 2018

@rzontar
Sorry about this, we'll consider to stop calling base.Exception.

You can disable injection by setting ExceptionTrackingTelemetryModule.EnableMvcAndWebApiExceptionAutoTracking to false

Simplest way to achieve it is through ApplicationInsights.config :

<Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web">
  <EnableMvcAndWebApiExceptionAutoTracking>false</EnableMvcAndWebApiExceptionAutoTracking>
</Add>

Note, you have ExceptionTrackingTelemetryModule in the config already.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants