2012-02-16 91 views
1

我试图添加使用​​分享您刚刚购买到我的网站的产品的功能。为此,您需要使用Facebook对用户进行身份验证并获得所需的权限。Facebook身份验证重定向循环

我有一些代码检查您是否经过身份验证,如果没有,将您重定向到Facebook oAuth页面进行身份验证。

然而,当从Facebook页面返回时,它会进入一个重定向循环:

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); 

} 

我的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然后知道我是通过身份验证的,所以它重定向我,导致循环。

+0

您提供的链接不提供解决方案,只是对问题的描述? – 2012-02-16 14:31:55

回答

0

我开发了一些示例代码,可在http://aka.ms/need01根本不使用cookie。基本上,它使用我编写的自定义身份验证模块(将会话状态存储在Windows Azure表中,但可以编写一个使用其他存储的模块),并将其状态的其余部分存储在URL中。 希望这可以帮助