Unable to load an external image in Silverlight - “ag e network error” exception

喜你入骨 提交于 2019-12-11 04:40:34

问题


I'm using Silverlight 4 and I'm experiencing the following problem: First off, the code:

BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
        bitmapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bitmapImage_DownloadProgress);
        bitmapImage.UriSource = new Uri("http://choteborsky.aspone.cz/Images/Label.png", UriKind.Absolute);
        bitmapImage.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(bitmapImage_ImageFailed);

The bitmapImage fires the ImageFailed event with the "ag e network exception". I seem to be unable to load any external images, no matter what I do. Is there something special I need to configure or why is it not working? Thanks


回答1:


The server where the image is hosted needs to have a crossdomain.xml file, allowing cross-domain requests. The file should, roughly, look like:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*" />
      </allow-from>
      <grant-to>
        <resource include-subpaths="true" path="/" />
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

That makes it wide open.




回答2:


Ok, I was able to find a workaround solution. Instead of trying to get the SL client to download the image from the server on which is sitting my ASP.NET app, I use a WCF service to stream the data directly to the SL client where I'm able to reconstruct them into BitmapImage type without any trouble



来源:https://stackoverflow.com/questions/3355070/unable-to-load-an-external-image-in-silverlight-ag-e-network-error-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!