Facebook crossdomain.xml silverlight 错误

发布于 2024-11-25 19:46:00 字数 738 浏览 0 评论 0原文

我的 Facebook 照片服务器上的 crossdomain.xml 有问题。当 Silverlight 请求 clientaccesspolicy.xml 时,第一个问题出现了 – Facebook 服务器返回 403 – 访问被拒绝,这很好,因为他们的服务器上也部署了 crossdomain.xml。然后,Silverlight 请求 crossdomain.xml,它得到的响应正是这样:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain- policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" secure="false" to-ports="*" />
    <site-control permitted-cross-domain-policies="master-only" />
</cross-domain-policy>

然后我用这个玩了一段时间,将该 crossdomain.xml 部署到我自己的服务器上,得到了相同的结果 - 一个安全异常。然后我开始将东西移出并得出结论:如果我只删除 to-ports="*" 属性,一切都会按预期工作?有谁知道如何克服这个问题,以前有人遇到过同样的问题还是我做错了什么?

I have a problem with crossdomain.xml that is located on Facebook photo servers. The first problem arises when Silverlight asks for clientaccesspolicy.xml – Facebook servers return 403 – Access Denied which is fine, since they also have crossdomain.xml deployed on their servers. Silverlight then asks for that crossdomain.xml and the response it gets is exactly this:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain- policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" secure="false" to-ports="*" />
    <site-control permitted-cross-domain-policies="master-only" />
</cross-domain-policy>

Then I played for a while with this, deployed that crossdomain.xml to my own servers and a got the same results – a security exception. Then I started moving things out and came to a conclusion that everything will work as desired if I only remove the to-ports="*" attribute? Does anyone has an idea how to overcome this, has anyone had the same problem before or is it something that I’m doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小霸王臭丫头 2024-12-02 19:46:00

我在尝试以编程方式从 Facebook 检索图像时遇到了同样的问题。奇怪的是,如果您将 Silverlight 图像控件指向 Facebook 图像 url,则图像将被检索并显示,不会出现错误。这让我开始思考,我想出了一个可行的解决方法,它似乎始终适合我的情况。我希望你也觉得它很有用。

var uri = new Uri("http://graph.facebook.com/mglace/picture/", UriKind.Absolute);
var bmp = new BitmapImage();

bmp.ImageOpened += (sender, e) => { /* Do something here with the sender (which is the BitmapImage) */ };
bmp.CreateOptions = BitmapCreateOptions.None;
bmp.UriSource = uri;

创建 BitmapImage 对象,为 ImageOpened 事件设置事件处理程序,并将 CreateOptions 属性设置为 BitmapCreateOptions.None 。最后,将 UriSource 设置为您要检索的 Facebook 图像。由于我们将 CreateOptions 设置为 None(默认值为 DelayedCreation),因此图像会立即下载。然后,您可以在 ImageOpened 事件处理程序中执行您想要的任何操作。

我想将此逻辑封装在我的服务层中,并加强错误处理等,因此我将其包装在 Reactive Extensions observable 中,以使其更易于使用。这是我的最终代码片段:

public IObservable<BitmapImage> GetProfilePhoto(string profileId)
{
    return Observable.Create<BitmapImage>(
        observer =>
            {
                // This handler handles a successful fetch
                EventHandler<RoutedEventArgs> openedHandler =
                    (sender, args) =>
                        {
                            try
                            {
                                observer.OnNext(sender as BitmapImage);
                                observer.OnCompleted();
                            }
                            catch (Exception ex)
                            {
                                observer.OnError(ex);
                            }
                        };

                // This handler handle a failure
                EventHandler<ExceptionRoutedEventArgs> failedHandler =
                    (sender, args) => observer.OnError(args.ErrorException);

                var url = string.Format("http://graph.facebook.com/{0}/picture/", profileId);
                var uri = new Uri(url, UriKind.Absolute);

                BitmapImage bmp = null;

                try
                {

                    Deployment.Current.Dispatcher.BeginInvoke(
                        () =>
                            {
                                bmp = new BitmapImage();

                                bmp.ImageOpened += openedHandler;
                                bmp.ImageFailed += failedHandler;

                                bmp.CreateOptions = BitmapCreateOptions.None;
                                bmp.UriSource = uri;
                            });
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);
                }

                return () =>
                            {
                                // Cleanup the event handlers
                                if (bmp != null)
                                {
                                    bmp.ImageOpened -= openedHandler;
                                    bmp.ImageFailed -= failedHandler;
                                }
                            };
            });
}

和用法:

GetProfilePhoto("mglace")
    .Subscribe(image => { /* Do something with the image in here*/  },
               error => { /* Handle any errors in here */ },
               () => { /* Finalization code goes here */ });

我希望有人发现这很有用。

I have run into the same issue while trying to programmatically retrieve images from Facebook. The strange part is that if you point a Silverlight image control to the Facebook image url, the image is retrieved and displayed without error. This got me thinking and I have come up with a viable workaround that seems to work consistently for my situation. I hope you find it useful too.

var uri = new Uri("http://graph.facebook.com/mglace/picture/", UriKind.Absolute);
var bmp = new BitmapImage();

bmp.ImageOpened += (sender, e) => { /* Do something here with the sender (which is the BitmapImage) */ };
bmp.CreateOptions = BitmapCreateOptions.None;
bmp.UriSource = uri;

Create a BitmapImage object, set an event handler for the ImageOpened event and set the CreateOptions property to BitmapCreateOptions.None. Finally, set the UriSource to the Facebook image you want to retrieve. The image is downloaded immediately because we set the CreateOptions to None (the default value is DelayedCreation). You can then perform any actions you would like in the ImageOpened event handler.

I wanted to encapsulate this logic in my service layer and beef up the error handling and such so I wrapped it in a Reactive Extensions observable to make it easier to use. Here is my final code snippet:

public IObservable<BitmapImage> GetProfilePhoto(string profileId)
{
    return Observable.Create<BitmapImage>(
        observer =>
            {
                // This handler handles a successful fetch
                EventHandler<RoutedEventArgs> openedHandler =
                    (sender, args) =>
                        {
                            try
                            {
                                observer.OnNext(sender as BitmapImage);
                                observer.OnCompleted();
                            }
                            catch (Exception ex)
                            {
                                observer.OnError(ex);
                            }
                        };

                // This handler handle a failure
                EventHandler<ExceptionRoutedEventArgs> failedHandler =
                    (sender, args) => observer.OnError(args.ErrorException);

                var url = string.Format("http://graph.facebook.com/{0}/picture/", profileId);
                var uri = new Uri(url, UriKind.Absolute);

                BitmapImage bmp = null;

                try
                {

                    Deployment.Current.Dispatcher.BeginInvoke(
                        () =>
                            {
                                bmp = new BitmapImage();

                                bmp.ImageOpened += openedHandler;
                                bmp.ImageFailed += failedHandler;

                                bmp.CreateOptions = BitmapCreateOptions.None;
                                bmp.UriSource = uri;
                            });
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);
                }

                return () =>
                            {
                                // Cleanup the event handlers
                                if (bmp != null)
                                {
                                    bmp.ImageOpened -= openedHandler;
                                    bmp.ImageFailed -= failedHandler;
                                }
                            };
            });
}

And usage:

GetProfilePhoto("mglace")
    .Subscribe(image => { /* Do something with the image in here*/  },
               error => { /* Handle any errors in here */ },
               () => { /* Finalization code goes here */ });

I hope someone out there finds this useful.

雪花飘飘的天空 2024-12-02 19:46:00

这个问题在 Silverlight 5 中仍然没有得到解决。Facebook 似乎也不担心。

This is still not resolved in Silverlight 5. Facebook doesn't seem concerned too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文