繁体   English   中英

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

[英]ASP.NET Core MVC application insights stopped working after upgrade to .NET Core 1.1.1

我有一个简单的ASP.NET核心应用程序,我在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应用程序洞察呢?

从ApplicationInsights 1.x到2.x有重大更改,这些更改记录在GitHub 发行说明中

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM