C# Facebook身份验证重定向循环
我正在尝试使用添加功能,将您刚购买的产品共享到我的网站。要做到这一点,您需要使用Facebook对用户进行身份验证,并获得所需的权限 我有一些代码可以检查您是否通过身份验证,如果没有,则会将您重定向到Facebook oAuth页面进行身份验证 但是,当页面从Facebook返回时,它会进入重定向循环:C# Facebook身份验证重定向循环,c#,facebook,facebook-c#-sdk,C#,Facebook,Facebook C# Sdk,我正在尝试使用添加功能,将您刚购买的产品共享到我的网站。要做到这一点,您需要使用Facebook对用户进行身份验证,并获得所需的权限 我有一些代码可以检查您是否通过身份验证,如果没有,则会将您重定向到Facebook oAuth页面进行身份验证 但是,当页面从Facebook返回时,它会进入重定向循环: var auth = new FacebookWebAuthorizer(); bool authorized = auth.FacebookWebRequest.IsAuthorized(n
var auth = new FacebookWebAuthorizer();
bool authorized = auth.FacebookWebRequest.IsAuthorized(new string[] { "publish_stream" });
if (authorized)
{
var client = new FacebookClient(auth.FacebookWebRequest.AccessToken);
Dictionary<string, object> args = new Dictionary<string, object>();
args["message"] = "This is a test.";
args["name"] = "";
args["link"] = "http://www.example.com/";
args["description"] = "Test link.";
client.Post("/me/feed", args);
}
else
{
var facebookClient = new FacebookOAuthClient();
var parameters = new Dictionary<string, object> {
{ "redirect_uri", "http://www.example.com/" },
{ "client_id", "xxxx" },
{ "scope", "publish_stream" }
};
Response.Redirect(facebookClient.GetLoginUrl(parameters).ToString(), true);
}
var auth=new FacebookWebAuthorizer();
bool authorized=auth.FacebookWebRequest.IsAuthorized(新字符串[]{“发布流”});
如果(授权)
{
var client=新的FacebookClient(auth.FacebookWebRequest.AccessToken);
Dictionary args=新字典();
args[“message”]=“这是一个测试。”;
参数[“名称”]=“”;
参数[“链接”]=“http://www.example.com/";
args[“说明”]=“测试链接。”;
client.Post(“/me/feed”,args);
}
其他的
{
var facebookClient=new facebookouthclient();
var参数=新字典{
{“重定向uri”http://www.example.com/" },
{“客户id”,“xxxx”},
{“范围”,“发布\u流”}
};
重定向(facebookClient.GetLoginUrl(parameters.ToString(),true);
}
我的web.config如下所示:
<configuration>
<configSections>
<section name="facebookSettings" type="Facebook.FacebookConfigurationSection" />
</configSections>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="facebookredirect.axd" verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</handlers>
</system.webServer>
<facebookSettings appId="xxxx" appSecret="xxxx" />
</configuration>
看起来我的网站没有识别出我已经通过了身份验证,所以它会重定向到Facebook登录。然后,Facebook知道我已通过身份验证,因此它将我重定向回,从而导致循环。像这样的循环通常是由于浏览器不喜欢接受第三方cookie造成的。尝试在Web服务器的响应中设置P3P头。有关更多信息,请参阅。快乐编码 我开发了一些完全不使用cookies的示例代码。基本上,它使用我编写的自定义身份验证模块(会话状态存储在WindowsAzure表中,但您可以编写使用另一个存储的会话),并将其其余状态存储在URL中。
希望这有帮助您提供的链接没有提供解决方案,只是对问题的描述?