我在带有 WebAPI 后端的 Angular 网站上使用 AI。
我正在设置 AuthenticatedUserContext,当向我的 API 发出 http 请求时,我可以看到信息被附加为 cookie。由于 CORS,存在飞行前 http OPTIONS 请求,并且正如预期的那样,该请求不包含 AI cookie。
查看 AI 中的遥测数据,我只能看到 OPTIONS 请求,但看不到 GET/POST 请求。会话和经过身份验证的用户信息未附加到 OPTIONS 请求。为什么记录了 OPTIONS 请求而没有记录 GET/POST?如何在没有 OPTIONS 请求的情况下记录 GET/POST 请求
ufeff
我在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;
}
}
}