第一次使用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