我有 .Net Framework 4.7.2 中的 Web 应用程序。它在 Azure 中部署为应用程序服务。我已经在其中启用了应用程序洞察。我可以阅读日志。但是当我点击“实时指标”时,它显示“不可用:无法连接到您的应用程序”
我在应用程序中添加了“Microsoft.ApplicationInsights”的最新包。同样在 Azure 门户中,在该应用服务中,在配置中添加了应用设置“APPINSIGHTS_INSTRUMENTATIONKEY”、“APPLICATIONINSIGHTS_CONNECTION_STRING”。
我还查看了 Microsoft 疑难解答文章“无法连接到您的应用程序的疑难解答”,但已执行该文章中提到的步骤。
我无法找到无法连接到应用程序的原因。有人可以帮我解决这个问题吗?
最佳答案
当您在 Azure 门户中创建应用服务时,它还将创建 App Insights 资源:
在发布网站之前,您必须将 Web 应用程序连接到关联的 App Insights 资源:
当您运行 Web 应用程序(打开 URL)时,请求率、时间将显示在实时指标中。正如您在下面的 Gif 中看到的,它显示了请求率、刷新主页的时间:
注意:
- 检查
Web.Config
文件 > 配置部分中是否有与 Application Insights 相关的包:
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<httpModules>
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="managedHandler" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
Packages.config 文件代码:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.ApplicationInsights" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Web" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.22.0-beta1" targetFramework="net472" />
<package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.8" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="4.1.0-preview1" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="7.0.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="7.0.0-preview.2.22152.2" targetFramework="net472" />
</packages>
引用这个MS Doc了解更多信息。
关于azure - "Not available: couldn' t 连接到您的应用程序“实时指标 Azure Application Insights,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75106329/