问题
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