【问题标题】:Silverlight XAP in Azure Cloud StorageAzure 云存储中的 Silverlight XAP
【发布时间】:2013-02-16 19:41:46
【问题描述】:

我有一个显示绿色矩形的 Silverlight xap。

此 xap 是 Azure 云中 ASP.NET 网站的一部分。

为了更轻松地升级 Xap,我已将其作为 blob 移至 Cloud Storage,并使用 https url 引用它。

现在 Xap 没有启动。不显示错误消息。 xap 应该在的地方有空白。

我已经在 Internet 上搜索了解决方案。当 Xap 访问另一个域上的服务或访问另一个域上的 blob 存储时,有许多解决方案。但这与我的问题不同。我的 xap 没有访问服务。它显示一个绿色矩形。

我该如何解决这个问题?

【问题讨论】:

  • 你可以使用一些网络流量调试器(fiddler 相当不错)来查看你的浏览器和远程应用程序之间的流量。该信息可能对解决您的问题至关重要。
  • 您是否在存储帐户的 $root blob 容器中添加了 ClientAccessPolicy 文件?还要检查包含 XAP 文件的 blob 容器是否可公开访问。您可以通过浏览器直接访问 XAP 文件来检查它 - https://.blob.core.windows.net//

标签: silverlight azure cross-domain blob


【解决方案1】:

感谢 Tom 和 Gaurav 让我到达那里。这是我的解决方案:

1) 创建了一个名为“clientaccesspolicy.xml”的文件。我用的是小写字母,不确定是否重要。在文件中输入以下内容:

<?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) 将此文件上传到您的 Blob 容器的根目录。使用 VS2010 访问我的 blob 存储,所以看不到根 ($root)。编写控制台应用程序以上传和设置内容类型。同样,不确定是否需要设置内容类型,但可能是个问题。

这是我使用的类:

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;

            }

        }

    }


}

}

然后在 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) 在我的 html 中,将 XAP url 从 HTTPS 更改为 HTTP。由于某种原因,这不起作用:

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

但是这样做了:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-28
    • 2013-01-13
    • 2014-03-29
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    相关资源
    最近更新 更多