谢谢汤姆和高拉夫把我带到那里。这是我的解决方案:
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"/>