Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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
C# 即使请求停止,代码也会输出两次错误?_C#_Asp.net - Fatal编程技术网

C# 即使请求停止,代码也会输出两次错误?

C# 即使请求停止,代码也会输出两次错误?,c#,asp.net,C#,Asp.net,我有个问题 当我在这段代码中遇到错误时,即使我调用的函数终止了响应,它也会输出两次错误,请注意OutputError: private dynamic GetOauthTokens(string code) { Dictionary<string, string> tokens = new Dictionary<string, string>(); string url = string.Format

我有个问题

当我在这段代码中遇到错误时,即使我调用的函数终止了响应,它也会输出两次错误,请注意OutputError:

   private dynamic GetOauthTokens(string code)
        {
            Dictionary<string, string> tokens = new Dictionary<string, string>();

            string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}",
                myAppId, HttpUtility.UrlEncode(myLoginRedirectUrl), myAppSecret, code);

            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string retVal = reader.ReadToEnd();

                    foreach (string token in retVal.Split('&'))
                    {
                        tokens.Add(token.Substring(0, token.IndexOf("=")),
                            token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    }
                }
            }
            catch (Exception exception)
            {
                OutputError("Code", exception.Message);
            }

            return tokens;
        }

出于某种原因,它吐了两次。。。我做错了什么?

设置调试器,在“ouputerror”函数的开头插入一个断点。如果它第二次击中它,检查堆栈跟踪以查看它来自何处。如果它来自ui两次,那么对firebug做同样的事情

这里有多个线程吗?这个方法可以同时运行两次吗?你知道我应该这样做的。谢谢你帮了一个傻瓜说出冷酷无情的事实。不用担心,达伦,很高兴我能帮上忙:)
 protected void OutputError(string error, string message)
        {
            object obj = new { Status = false, Error = error, Message = message };
            string objJson = JsonConvert.SerializeObject(obj);

            myHttpContext.Response.Write("LinkedLook.getJson(" + objJson + ");");
            myHttpContext.Response.End();
        }