我遇到了问题。
当我在这段代码上出错时,即使我调用的函数杀死了响应,它也输出错误两次,注意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;
}
这是我处理它的地方:
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();
}
出于某种原因,它吐了两次......我做错了什么?
答案 0 :(得分:1)
设置调试器,在“ouputerror”函数的开头粘贴一个断点。如果它再次击中它,请检查堆栈跟踪以查看它的来源。如果它来自ui两次然后用firebug做同样的事情。