第一次使用Silverlight!遵循在線教程。我創建的應用程序允許用戶使用WebClient從Digg網站搜索故事,並將它們顯示在Silverlight控件的數據網格中。WebClient.DownloadStringAsync在Silverlight中拋出安全異常
下面的代碼:
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
string topic = txtTopic.Text;
string diggUrl = String.Format("http://services.digg.com/stories/topic/{0}?count=20&appkey=http%3A%2F%2Fscottgu.com", topic);
WebClient diggService = new WebClient();
diggService.DownloadStringCompleted += new DownloadStringCompletedEventHandler(diggService_DownloadStringCompleted);
diggService.DownloadStringAsync(new Uri(diggUrl));
}
void diggService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
DisplayStories(e.Result);
}
}
每當我把一個破發點上diggService_DownloadStringCompleted
事件處理程序,然後點擊搜索按鈕e.Error
總是等於沒有消息和相同的內部異常的System.Security.SecurityException輸入「安全錯誤」消息。堆棧跟蹤是:
在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,對象狀態)
在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult的asyncResult)
在系統.Net.WebClient.GetWebResponse(WebRequest的要求,IAsyncResult的結果)
在System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult的結果)
後有些沉重谷歌上搜索我見過peopl提及一個crossdomain.xml文件。不完全確定這是什麼,但我添加了一個到運行Silverlight控件的Web服務器的根目錄並添加了以下文本。沒有任何區別:
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
這是怎麼回事?
你解決了這個問題嗎?我有同樣的問題 – Andrew 2011-06-09 10:11:33