我有以下方法,它基本上是使用他们的 Facebook 凭据对用户进行身份验证。出于某种原因,我WebException
在尝试处理授权密钥(代码)时遇到了问题。因此,我尝试读取响应流以了解发生了什么,但在读取流时我不断收到错误。这是我的代码:
private void OnAuthCallback(HttpContextWrapper context, WebServerClient client)
{
try
{
IAuthorizationState authorizationState = client.ProcessUserAuthorization(context.Request);
AccessToken accessToken = AccessTokenSerializer.Deserialize(authorizationState.AccessToken);
String username = accessToken.User;
context.Items[USERNAME] = username;
}
catch (ProtocolException e)
{
if (e.InnerException != null)
{
String message = e.InnerException.Message;
if (e.InnerException is WebException)
{
WebException exception = (WebException)e.InnerException;
var responseStream = exception.Response.GetResponseStream();
responseStream.Seek(0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader(responseStream))
{
message = sr.ReadToEnd();
}
}
EventLog.WriteEntry("OAuth Client", message);
}
}
}
如果我删除该responseStream.Seek(0, SeekOrigin.Begin);
行,它会给我ArgumentException
一条消息,指出流不可读。有了这条线,它告诉我我无法操纵已经关闭的流。这条流是如何关闭的?为什么我不能从中读取?