【问题标题】:How to turn off Application insights javascript in embedded cshtml views如何在嵌入式 cshtml 视图中关闭应用程序洞察力 javascript
【发布时间】:2018-08-18 00:46:41
【问题描述】:

我有一个视图 Email1.cshtml (Build Action=Embedded Resource):

@model Email1Model;

<html>
<head>
</head>
<body>
  <h1>Hello, @Model.Name</h1>
</body>
</html>

我使用ViewRenderService 将cshtml 视图呈现为字符串。唯一的区别是我使用IRazorViewEngine.GetView() 而不是 FindView();

但是,在输出中我有一些应用洞察力:

<html> <head>
    <script type="text/javascript">
        var appInsights=window.appInsights||function(config){....);

        window.appInsights=appInsights;
        appInsights.trackPageView();

    </script> </head> <body>
    <h1>Hello, Liero</h1> </body> </html>

在startup.cs中:

services.AddApplicationInsightsTelemetry(opt => opt.InstrumentationKey = appInsightsKey);

问题:

如何在使用 ViewRenderService 渲染的特定视图中关闭 javascript?

【问题讨论】:

    标签: razor asp.net-core asp.net-core-mvc asp.net-core-2.0 azure-application-insights


    【解决方案1】:

    如果您的 _layout.cshtml 有 @Html.Raw(JavaScriptSnippet.FullScript) 会将应用程序洞察 javascript 注入每个页面,您可以尝试在 _layout.cshtml 中添加条件:

    @if (condition true for instrumenting)
    {
        @Html.Raw(JavaScriptSnippet.FullScript)
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      相关资源
      最近更新 更多