public FacebookContextSettings()
        {
            FacebookWebContext facebookContext = FacebookWebContext.Current;

            IFacebookApplication  settings;
            FacebookSignedRequest signedRequest;

            if (facebookContext.SignedRequest == null)
            {
                // ajax requests won't have a signed request, so we need to build it from the current http request
                // see http://facebooksdk.codeplex.com/discussions/251878
                settings = FacebookApplication.Current;

                try
                {
                    signedRequest = FacebookSignedRequest.Parse(settings, SignedRequest);
                }
                catch (Exception exception)
                {
                    // Facebook posts to the iframe, but only IE supports this so the first request will always fail for non IE browsers
                    if (HttpContext.Current.Request.Browser.Browser.Contains("IE"))
                    {
                        throw;
                    }

                    // it doesn't break anything so we'll throw a custom exception so that we can filter it out later
                    InvalidSignedRequestException signedRequestException =
                        new InvalidSignedRequestException("Invalid SignedRequest - Non - IE (" + SignedRequest + ")", exception);
                    throw signedRequestException;
                }
            }
            else
            {
                settings      = facebookContext.Settings;
                signedRequest = facebookContext.SignedRequest;
            }

            CanvasPage  = settings.CanvasPage;
            AccessToken = signedRequest.AccessToken;
            AppId       = settings.AppId;
            UserId      = signedRequest.UserId;
        }
コード例 #2
0
        private FacebookSignedRequest ParseSignedRequest(IFacebookApplication settings)
        {
            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                HttpContextWrapper contextWrapper = new HttpContextWrapper(context);
                if (contextWrapper.Request.IsAjaxRequest())
                {
                    // ajax requests won't have a signed request, so we need to build it from the current http request
                    // see http://facebooksdk.codeplex.com/discussions/251878

                    try
                    {
                        return(FacebookSignedRequest.Parse(settings, SignedRequest));
                    }
                    catch (Exception exception)
                    {
                        // Facebook posts to the iframe, but only IE supports this so the first request will always fail for non IE browsers
                        if (context.Request.Browser.Browser.Contains("IE"))
                        {
                            throw;
                        }

                        // it doesn't break anything so we'll throw a custom exception so that we can filter it out later
                        InvalidSignedRequestException signedRequestException =
                            new InvalidSignedRequestException(
                                "Invalid SignedRequest - Non - IE (" + SignedRequest + ")",
                                exception);
                        throw signedRequestException;
                    }
                }
            }

            return(null);
        }