Search code examples
c#azureasp.net-coreazure-managed-identity

Implemented Managed Identity for App Service to access Application Insights .NET Core 3.1


I implemented my webapp so that it is able to log data to Application Insights through managed identity. I noticed now that after my implementation I am getting an error on the home page of the webapp:

enter image description here

This is the page that comes up on my app when loads up when a valid route is not found. If I was to go to the Console this is what I see: enter image description here

Like I mentioned, this came after Managed Identity was implemented.


Solution

  • Thanks @Panagiotis Kanavos for the comments.

    • Yes, .NET Core 3.1 is OutofSupport and your App may not work as expected.

    • If you still want to continue with the old Core 3.1 version, check the below steps.

    Thanks @Stefano Demiliani for the clear explanation.

    I have taken references from MSDoc and demiliani

    • To work with Managed Identity, you need to assign a new role Monitoring Metrics Publisher in Application Insights.

    enter image description here

    • Even the Properties section in Application Insights says the same. enter image description here

    • Disable the Local Authentication.

    My .csproj file:

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>    
      <TargetFramework>netcoreapp3.1</TargetFramework>    
      <ApplicationInsightsResourceId>/subscriptions/**********/resourceGroups/********/providers/microsoft.insights/components/Core3AppInsights</ApplicationInsightsResourceId>   
        <UserSecretsId>********</UserSecretsId>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Azure.Identity" Version="1.10.4" />
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
        <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
      </ItemGroup>
    </Project>
    

    In Startup.cs file, add under ConfigureServices,services.AddApplicationInsightsTelemetry();.

    enter image description here