locked
Blobs, REST, Firefox and Silverlight = Security Error RRS feed

  • Question

  • Hello,

    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 IE produces the expected result - the size of a blob uploaded to Azure Storage. Unfortunately, the same application, when ran in Firefox, produces a "Security Error" with no further indication of what might be wrong.

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

    EDIT:
    The same issue occurs in Chrome.

    EDIT 2:
    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 and crossdomain XML files. Again - the code works in IE, but fails to function in Firefox / Chrome.

    Tuesday, August 19, 2014 12:38 PM

Answers

  • 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.

    Friday, August 22, 2014 10:32 AM

All replies

  • Hello Bender,

    Thanks for posting here!

    You can try either of these steps mentioned below:

    Try to enable web server logging (you can find more info e.g. here http://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/ ) and check if you can find any failed requests in those logs.

    Another good thing to check would be eventlog.xml file which gets generated in your logs folder (you can access it e.g. using FTP) and should be somewhere next to wwwroot folder. If you see the file there, your application might crash from time to time and you will find the exception in that file.

    If it is working fine on Internet Explorer and errors out in Mozilla Firefox and Chrome then you might want to reset your browser settings.

    Mozilla Firefox Settings:

    •  "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    • "Remove the Cookies" from sites that cause problems: Tools > Options > Privacy > Cookies: "Show Cookies" 

    Chrome Settings:

    https://support.google.com/chrome/answer/3296214?hl=en

    Disclaimer: The Reset Settings feature might reset security settings or privacy settings that you added to the list of Trusted Sites. The Reset Settings feature might also reset parental control settings. We recommend that you note these sites before you use the Reset Settings feature.

    Hope that helps!

    Best Regards,

    Sadiqh Ahmed

    Tuesday, August 19, 2014 2:54 PM
  • Hi Bender,

    Thanks for your posting!

    For this issue, I think it may be the browser incompatibility. You could update or change your Firefox or Chrome version and try it. And I recommend you could refer to this "Some Caveats" part in Gaurv's blog (http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/ ). For Silverlight, You also could view Smarx's blog (http://blog.smarx.com/posts/uploading-windows-azure-blobs-from-silverlight-part-1-shared-access-signatures )  and try his code sample.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 20, 2014 6:20 AM
  • Enabling logging on the storage didn't show anything. Enabling logging on an Azure site is pointless, as the problem might just as well originate from a Silverlight hosted on my own IIS.

    Furthermore, suggestions to "clear the cache" (which I do all the time anyway when testing SL applications) or "reinstall the browser" seem a bit condescending. The same issue occurs on other users systems, not just mine. The same thing happens to everyone I asked to test this in my workplace, as well as my machine at home (so it's not a firewall / location issue). I'll test this on another Firefox version, but even if this works in an older version it's hardly a solution. (EDIT: I've tried it using an old Firefox Portable version - same thing...)

    Finally, "Some Caveats", as described in Gaurv's blog, are about uploading large files. My problem is more general - merely accessing blobs is problematic in other browsers. I've also tried the code sample - I've edited the Web part of the solution to use a fixed URL for a test container with SAS allowing all access (rather than creating/getting it dynamically via code-behind on Default.aspx.cs). Just as before, the application worked in IE but failed to work on Firefox. While this may just as well be a matter of browser incompatibility, it seems to be undocumented and untested. A workaround would be most welcome.




    Wednesday, August 20, 2014 7:54 AM
  • 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.

    Friday, August 22, 2014 10:32 AM