【发布时间】:2010-11-24 10:19:57
【问题描述】:
第一次使用 Silverlight!遵循在线教程。我正在创建一个应用程序,它允许用户使用 WebClient 从 Digg 网站搜索故事,并将它们显示在 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)
在 System.Net.WebClient.GetWebResponse(WebRequest 请求,IAsyncResult 结果)
在 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult 结果)
经过一番繁重的谷歌搜索后,我看到人们提到了一个 crossdomain.xml 文件。不完全确定这是什么,但我在运行 Silverlight 控件的 Web 服务器的根目录中添加了一个,并添加了以下文本。没有任何区别:
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
发生了什么事?
【问题讨论】:
-
您解决了吗?我也有同样的问题
标签: c# silverlight webclient