gpt4 book ai didi

c# - 如何为 DotNetOpenAuth 设置返回 url

转载 作者:太空狗 更新时间:2023-10-29 21:36:40 24 4
gpt4 key购买 nike

我正在使用 DotNetOpenAuth 登录 Facebook
这是代码:

var facebookClient = new FacebookClient
{
ClientIdentifier = "appId",
ClientSecret = "appSecret"
};
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
if (authorization == null)
{
// Kick off authorization request
facebookClient.RequestUserAuthorization();
}
else
{

var request =
WebRequest.Create("https://graph.facebook.com/me?access_token=" +
Uri.EscapeDataString(authorization.AccessToken));

using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var graph = FacebookGraph.Deserialize(responseStream);
lblFacebookUserName.Text = HttpUtility.HtmlEncode(graph.Name);
}
}
}

因为我使用的是自定义 url 重写器,所以我在登录后收到错误消息,因为返回的 url 类似于

~/foo/foo.aspx?labg=en

我希望它硬编码为

~/foo/foo

任何帮助将不胜感激

最佳答案

您需要使用回调 URL 初始化 AuthorizationState 对象,并将其传递给稍微不同的方法:

// Kick off authorization request
var authorizationState = new AuthorizationState()
{
Callback = new Uri(Request.Url, Page.ResolveUrl("~/foo/foo"));
};
facebookClient.PrepareRequestUserAuthorization(authorizationState).Send();

关于c# - 如何为 DotNetOpenAuth 设置返回 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3466540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com