0
votes

I'm trying to access Azure Storage blobs (via SAS string) from a Silverlight application. A clientaccesspolicy.xml is present in the $root blob container, allowing Silverlight access.

I've created a sample Silverlight application with just one button. The button executes the following code:

        var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri("http://[mystoragename].blob.core.windows.net/[mycontainername]/[myfilename]?[sasString]"));
        request.Method = "GET";
        request.BeginGetResponse(r =>
        {
            try
            {
                var response = request.EndGetResponse(r);
                using (var s = response.GetResponseStream())
                {
                    this.Dispatcher.BeginInvoke(() => MessageBox.Show(s.Length.ToString()));
                }
            }
            catch(Exception ex)
            {
                this.Dispatcher.BeginInvoke(() => MessageBox.Show(ex.Message));
            }
        }, null);

Running this code on Internet Explorer produces the expected result - the size of a blob uploaded to Azure Storage. Unfortunately, the same application, when ran in Firefox or Chrome, produces a "Security Error" with no further indication of what might be wrong.

The SAME issue occurs when I try to download a file from a PUBLIC blob container (same code as above, only different URL). The public blob container also has it's own clientaccesspolicy.xml and crossdomain.xml files (albeit I don't think these are needed). Again - the code works in IE, but fails to function in Firefox / Chrome.

What could be the issue? Where should I even begin looking for one?

1
@SeanCocteau I've tried using WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp); WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp); lines already (since I also wanted PUT functionality in my SL application). It still doesn't work. As for Fiddler, I'm having some really annoying issues with it ATM, and I can't get it to track SL requests from anything but IE.Shaamaan
My money would be looking at how Silverlight is playing with its requests and eliminating any problems with that. The simpliest way of achieving this would be using Fiddler.SeanCocteau

1 Answers

0
votes

I found a valid workaround.

I've created an ASHX handler on the web site which is hosting the Silverlight application. This handler basically "redirects" a HttpWebRequest to Azure Storage.

        var url = String.Format("http://{0}.blob.core.windows.net/{1}/{2}{3}", accountName, containerName, blobName, sas);
        var request = (HttpWebRequest)WebRequest.Create(url);
        try
        {
            var response = request.GetResponse();
            context.Response.ContentType = response.ContentType;
            using (var stream = response.GetResponseStream())
            {
                stream.CopyTo(context.Response.OutputStream);
            }
        }
        catch
        {
            context.Response.End();
        }

Where the parameters used in building the url are passed as query string parameters to the ASHX handler. While not ideal (an ideal solution would be connecting from SL directly to Azure Storage), this works fast enough and doesn't seem to use much resources.