简体   繁体   English

Azure云存储中的Silverlight XAP

[英]Silverlight XAP in Azure Cloud Storage

I have a Silverlight xap that displays a green rectangle. 我有一个显示绿色矩形的Silverlight Xap。

This xap is part of an ASP.NET website in the Azure cloud. 此xap是Azure云中ASP.NET网站的一部分。

To make it easier to upgrade the Xap, I have moved it into Cloud Storage as a blob, and reference it with an https url. 为了更轻松地升级Xap,我将其作为Blob移到了Cloud Storage中,并使用https url对其进行了引用。

Now the Xap does not start. 现在,Xap无法启动。 No error message is displayed. 没有错误信息显示。 There is white space where the xap should be. xap应该在空白处。

I have searched the Internet for a solution. 我已经在互联网上搜索了解决方案。 There are many solutions for when the Xap is accessing a service on another domain, or accessing blob storage on another domain. 当Xap访问另一个域上的服务或访问另一个域上的Blob存储时,有许多解决方案。 But this is not the same as my problem. 但这与我的问题不同。 My xap does not access a service. 我的xap无法访问服务。 It displays a green rectangle. 它显示一个绿色矩形。

How can I fix this? 我怎样才能解决这个问题?

Thank you Tom and Gaurav for getting me there. 谢谢汤姆和高拉夫带我到那里。 Here is my solution: 这是我的解决方案:

1) Created a file called "clientaccesspolicy.xml". 1)创建一个名为“ clientaccesspolicy.xml”的文件。 I used lower-case letters, not sure it matters. 我使用小写字母,不确定是否重要。 In the file put the following: 在文件中输入以下内容:

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

2) Uploaded this file to the root of your blob container. 2)将此文件上传到您的Blob容器的根目录。 Using VS2010 to access my blob storage, so cannot see the root ($root). 使用VS2010访问我的Blob存储,因此看不到根目录($ root)。 Wrote console app to upload and set the content-type. 编写控制台应用程序以上传并设置内容类型。 Again, not sure if setting the content-type is necessary, but could be a gotcha. 同样,不确定是否必须设置content-type,但这可能是一个陷阱。

This is the class I used: 这是我使用的类:

namespace ConsoleApplication
{

/// <summary>
/// 
/// </summary>
public class BlobStorageContainer
{

    /////////////////////////////////////////////////////////////
    // Constants

    private const string BLOB_CONNECTION = <get this from the windows azure portal>;

    public const string ROOT_CONTAINER_NAME = "$root";


    /////////////////////////////////////////////////////////////
    // Attributes

    private static CloudStorageAccount _storageAccount;

    private static CloudBlobClient _blobClient;

    private CloudBlobContainer _container;


    /////////////////////////////////////////////////////////////
    // Construction

    static BlobStorageContainer()
    {

        // Create storage account
        _storageAccount = CloudStorageAccount.Parse(BLOB_CONNECTION);

        // Construct cloud blob client
        _blobClient = _storageAccount.CreateCloudBlobClient();

    }

    public BlobStorageContainer(string strContainer)
    {

        // Get the audio-files container
        _container = _blobClient.GetContainerReference(strContainer);

        try
        {

            // If container does not exist...
            if (!_container.Exists())
            {

                // Create container
                _container.CreateIfNotExists();

                // Set permissions
                BlobContainerPermissions permissions = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob };
                _container.SetPermissions(permissions);

            }

        }
        catch (Exception x)
        {

            // Reset reference
            _container = null;

            // throw back
            throw x;

        }
    }


    /////////////////////////////////////////////////////////////
    // Operations

    public void SetContentType(string strName, string strContentType)
    {

        // Retrieve the block-blob
        CloudBlockBlob blob = _container.GetBlockBlobReference(strName);
        if (blob.Exists())
        {

            // If props need changing...
            if (blob.Properties.ContentType != strContentType)
            {

                // Set properties
                blob.Properties.ContentType = strContentType;
                blob.SetProperties();

            }

        }

    }

    public void UploadFile(string strFilepath,string strName)
    {

        // Get blob
        CloudBlockBlob blob = _container.GetBlockBlobReference(strName);

        // Open file
        using(FileStream fs = new FileStream(strFilepath,FileMode.Open,FileAccess.Read))
        {
            blob.UploadFromStream(fs);
        } // using fs

    }

    public void WalkBlobs(Func<string, long, string, bool> fnCallback)
    {

        // Loop through the blobs
        foreach (IListBlobItem loop in _container.ListBlobs())
        {

            // If this is a block blob...
            if (loop is CloudBlockBlob)
            {

                // Get the blob
                CloudBlockBlob blob = loop as CloudBlockBlob;

                // Callback function
                bool bContinue = fnCallback(blob.Name, blob.Properties.Length, blob.Properties.ContentType);
                if (!bContinue)
                    break;

            }

        }

    }


}

} }

and then did this in the Main function: 然后在Main函数中执行以下操作:

// Open container
BlobStorageContainer container = new BlobStorageContainer(BlobStorageContainer.ROOT_CONTAINER_NAME);

// Upload file
container.UploadFile(@"D:\Workspace\clientaccesspolicy.xml", "clientaccesspolicy.xml");

// Set content type
container.SetContentType("clientaccesspolicy.xml", "text/xml");

3) In my html, changed XAP urls from HTTPS to HTTP. 3)在我的html中,将XAP URL从HTTPS更改为HTTP。 For some reason, this DID NOT WORK: 由于某些原因,此DID不起作用:

<param name="source" value="https://<blobaccount>.blob.core.windows.net/container1/MySilverlight.xap"/>

but this did: 但是这样做:

<param name="source" value="http://<blobaccount>.blob.core.windows.net/container1/MySilverlight.xap"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM