升级到.NET Core 1.1.1后,ASP.NET Core MVC应用程序洞察停止工作。

8
我有一个简单的ASP.NET Core应用程序,我在2016年12月曾经在上面工作过。它可以正常使用应用程序洞察和遥测功能。
现在,4个月后,我想拾起这项工作,并从.NET Core 1.1.0升级到1.1.1。在此过程中,包Microsoft.ApplicationInsights.AspNetCore从版本1.0.2更新到版本2.0.0
不幸的是,这导致我的应用程序停止工作,特别是出现以下错误:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

/Views/Shared/_Layout.cshtml

'IHtmlHelper<dynamic>' does not contain a definition for 'ApplicationInsightsJavaScript' and no extension method 'ApplicationInsightsJavaScript' accepting a first argument of type 'IHtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)
+
    @Html.ApplicationInsightsJavaScript(TelemetryConfiguration)

Show compilation source
#pragma checksum "/Views/Shared/_Layout.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "050a2afdfb4a44e17be72e76627a3d3a0d0b7d5a"
namespace AspNetCore
{
#line 1 "/Views/_ViewImports.cshtml"

屏幕:

输入图像描述

从 project.json 升级到新的 csproj 并使用新的 Visual Studio 2017 并没有帮助。

看起来 ApplicationInsightsJavaScript 基本上已经从 API 中移除了。那么,我该如何启用 JavaScript 应用程序洞察呢?


这是一个重大的发布版本,其中包含了破坏性变更。 - Tseng
1个回答

23

有关ApplicationInsights 1.x升级到2.x的重大更改已在GitHub的发布说明中记录。

  • 该版本包含对SDK内部进行了重新编写,以更好地与.NET Core集成和初始化。
  • UseApplicationInsightsRequestTelemetry 已过时,它执行的逻辑现在已自动处理,因此应从 Startup.cs 中删除对此方法的调用。
  • UseApplicationInsightsExceptionTelemetry 已过时,异常遥测现在已在内部自动处理。您应该从 Startup.cs 中删除对此方法的调用,否则将会报告重复的异常遥测。
  • JavaScript片段的MVC依赖项已被移除,因此现在需要进行以下更改才能包含JavaScript片段:
    • 在 _ViewImports.cshtml 中,将@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration替换为@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
    • 在 _Layout.cshtml 中,将@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)替换为@Html.Raw(JavaScriptSnippet.FullScript)

只是补充一下,当替换 ApplicationInsightsJavaScript 部分时,您需要在布局文件顶部添加 @inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet - Lloyd Powell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接