謝謝湯姆和高拉夫讓我到那裏。這是我的解決方案:
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;
}
}
}
}
}
,然後在主函數這樣做:
// 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網址,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"/>
你可以使用一些網絡流量的調試器(提琴手是相當不錯的),看看你有你的瀏覽器和什麼之間的交通遠程應用。這些信息對解決您的問題可能至關重要。 – Tom 2013-02-16 22:03:45
您是否在存儲帳戶的$ root blob容器中添加了ClientAccessPolicy文件?同時檢查包含XAP文件的blob容器是否可公開訪問。您可以通過瀏覽器直接訪問XAP文件進行檢查 - https:// .blob.core.windows.net//。 –
2013-02-17 04:44:42