无法从我的intrumentationKey获取我的appId:Appinsight

时间:2018-11-09 16:36:10

标签: .net azure azure-application-insights

我正在尝试通过这种方法从仪器密钥中获取我的AddId:

ApplicationInsightsApplicationIdProvider toto = new ApplicationInsightsApplicationIdProvider();
            bool test = toto.TryGetApplicationId(_configuration["ApplicationInsights:InstrumentationKey"], out string applicationId);

但是我得到的结果总是错误的,就像我的应用洞察力不存在一样。

有人知道为什么吗?

1 个答案:

答案 0 :(得分:0)

我能够手动执行此操作:

   private bool TryGetApplicationId(string intrumentationKey, out string appId)
            {
                RestClient restClient = new RestClient("https://dc.services.visualstudio.com");
                RestRequest request = new RestRequest(string.Format("api/profiles/{0}/appId", intrumentationKey), Method.GET);
                RestResponse response = (RestResponse) restClient.Execute(request);
                appId = response.Content;
                return response.IsSuccessful;
            }