【问题标题】:Application Insights: HTTP OPTIONS recorded but GET/POST ignoredApplication Insights:记录了 HTTP 选项,但忽略了 GET/POST
【发布时间】:2017-08-05 04:57:45
【问题描述】:

我在一个带有 WebAPI 后端的 Angular 网站上使用 AI。

我正在设置 AuthenticatedUserContext,当对我的 API 进行 http 请求时,我可以看到信息作为 cookie 附加。由于 CORS,存在一个飞行前 http OPTIONS 请求,并且正如预期的那样,此请求不包括 AI cookie。

查看 AI 中的遥测数据,我只能看到 OPTIONS 请求,但看不到 GET/POST 请求。会话和经过身份验证的用户信息未附加到 OPTIONS 请求。为什么记录了 OPTIONS 请求而不记录 GET/POST?如何在没有 OPTIONS 请求的情况下记录 GET/POST 请求



【问题讨论】:

  • 要么修改请求以便不需要预检,要么让服务器正确响应预检,以便浏览器可以通过正确的获取/发布请求跟进它。
  • @KevinB “通过正确的获取/发布请求跟进”是什么意思? get/post 请求在 pre-flight 请求后成功完成,唯一的问题是它们没有记录在 AI 的遥测中。
  • 我当时理解错了。我的印象是它们没有发生,这通常表明存在 cors 错误。

标签: angularjs cookies cors azure-application-insights http-options-method


【解决方案1】:

我在msdn论坛上回复了你。也在这里回复:

我想你点击了bug。 GitHub 问题有一个解决方法建议您可以尝试

过滤使用这个doc。你会有这样的代码:

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

public class SuccessfulDependencyFilter : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // Link processors to each other in a chain.
    public SuccessfulDependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        if (!OKtoSend(item)) { return; }

        this.Next.Process(item);
    }

    private bool OKtoSend (ITelemetry item)
    {
        var request = item as RequestTelemetry;

        //if its not a Request, return true.  We don't care to filter it here
        if (request == null) return true;

        if (request.Name.StartsWith("OPTIONS")) //CORS Pre Flight Request
        {
            return false;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 2017-12-19
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多