开发者

How to set return url for DotNetOpenAuth

开发者 https://www.devze.com 2023-01-11 11:22 出处:网络
I\'m using DotNetOpenAuth to sign in to Facebook. Here is the code: var facebookClient = new FacebookClient

I'm using DotNetOpenAuth to sign in to Facebook.

Here is the code:

var facebookClient = new FacebookClient
{
    ClientIdentifier = "appId",
    ClientSecret = "appSecret"
};
IAuthorizationState authorizati开发者_JAVA技巧on = 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);
        }
    }
}

Since I'm using custom url rewriter, I'm receiving an error after login because return url is something like

~/foo/foo.aspx?labg=en

and I want it to hard code it to

~/foo/foo

Any help would be appreciated


You need to initialize the AuthorizationState object with a callback URL and pass that in to a slightly different method:

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

精彩评论

暂无评论...
验证码 换一张
取 消