Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Application Insights希望我使用带有固定JSON键的Javascript_Javascript_Json_Azure_Azure Application Insights - Fatal编程技术网

Application Insights希望我使用带有固定JSON键的Javascript

Application Insights希望我使用带有固定JSON键的Javascript,javascript,json,azure,azure-application-insights,Javascript,Json,Azure,Azure Application Insights,当我进入我的开发web应用程序的Azure Application Insights资源并查看使用情况时,我看到一个链接,上面写着“了解如何收集页面视图数据” 链接给出了下面的代码,但它有一个固定的instrumentationKey设置为JSON变量。我希望它使用iKey的web.config AppSettings值 我可以将iKey转换成javascript变量,但如何将其转换成JSON 是否有更好的方法将应用程序洞察与app.config iKey一起使用 var iKey = '<

当我进入我的开发web应用程序的Azure Application Insights资源并查看使用情况时,我看到一个链接,上面写着“了解如何收集页面视图数据”

链接给出了下面的代码,但它有一个固定的instrumentationKey设置为JSON变量。我希望它使用iKey的web.config AppSettings值

我可以将iKey转换成javascript变量,但如何将其转换成JSON

是否有更好的方法将应用程序洞察与app.config iKey一起使用

var iKey = '<%=ConfigurationManager.AppSettings["iKey"].ToString() %>';
var appInsights = window.appInsights || function (config) {
    function r(config) {
        t[config] = function () {
            var i = arguments;
            t.queue.push(function () {
                t[config].apply(t, i)
            })
        }
    }
    var t = {
        config: config
    },
      u = document,
      e = window,
      o = "script",
      s = u.createElement(o),
      i, f;
    for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
    return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
        var s = f && f(config, r, u, e, o);
        return s !== !0 && t["_" + i](config, r, u, e, o), s
    }), t
}({
    instrumentationKey: "1x1111x1-1x1x-1x1x-xx11-xxxxxxxxxxxx" // I would like to use iKey here
});

window.appInsights = appInsights;
appInsights.trackPageView();
var-iKey='';
var appInsights=window.appInsights | |函数(配置){
函数r(配置){
t[config]=函数(){
变量i=参数;
t、 queue.push(函数(){
t[config].apply(t,i)
})
}
}
变量t={
config:config
},
u=文件,
e=窗口,
o=“脚本”,
s=u.createElement(o),
i、 f;
对于(s.src=config.url | |“//az416426.vo.msecnd.net/scripts/a/ai.0.js”,u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=[“事件”,“异常”,“度量”,“页面视图”,“跟踪”];i.length;)r(“跟踪”+i.pop();
返回r(“setAuthenticatedUserContext”)、r(“clearAuthenticatedUserContext”)、config.disableExceptionTracking | | |(i=“onerror”,r(““+i”),f=e[i],e[i]=函数(config,r,u,e,o){
var s=f&&f(配置、r、u、e、o);
返回s!==!0&&t[“”+i](配置,r,u,e,o),s
}),t
}({
instrumentationKey:“1x111x1-1x1x-1xx1x-xx11-xxxxxxxxxxx”//I我想在这里使用iKey
});
window.appInsights=appInsights;
appInsights.trackPageView();

为什么不能将“1xx1xx1-1…”替换为
iKey
?我收到以下消息:加载资源失败:服务器响应状态为400(无效检测密钥)ai.0.js:1 ai(内部):非usract\u OnError消息:“发送遥测失败”。道具:{消息:{\itemsReceived\:3,\itemsacceptied\:0,\errors\:[{\index \:0\statusCode \:400\message\:\Invalid instrumentation key\},{\index \:1\statusCode \:400\message\:\Invalid instrumentation key\},{\index \:2\statusCode \:400\message\:\Invalid instrumentation key\}在你的例子中,你的代码可能是
instrumentationKey:iKey
吗?看起来应该可以。我想如果你调试,js中iKey的值并不是你期望的值。你能粘贴或编辑上面的代码片段来显示代码中的确切iKey吗?iKey不是秘密(任何看到你的页面的人都可以看到代码中的ikey)。确保你使用了正确的键,我花了将近一个小时才意识到我使用的是订阅键而不是插入键。。。