WebClient.DownloadStringAsync在Silverlight抛出安全例外 [英] WebClient.DownloadStringAsync throwing Security Exception in Silverlight

查看:192
本文介绍了WebClient.DownloadStringAsync在Silverlight抛出安全例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Silverlight有史以来第一次!下面的在线教程。我创建一个应用程序,它允许用户搜索使用的WebClient从Digg的网站的故事,并将其显示在一个Silverlight控件的数据网格。

First time using Silverlight ever! Following an online tutorial. I'm creating an app which allows the user to search for stories from the Digg website using a WebClient and displays them in a data grid in a Silverlight control.

这里的代码:

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同类型的同一条消息安全错误。。堆栈跟踪为:

Whenever I put a break point on the diggService_DownloadStringCompleted event handler and click the search button e.Error always equals a System.Security.SecurityException with no message and an inner exception of the same type with a message of 'Security error.'. The stack trace is:

在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,对象状态)

at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)

在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult的asyncResult)

at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

在System.Net.WebClient.GetWebResponse(WebRequest的要求,IAsyncResult的结果)

at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)

在System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult的结果)

at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)

有些沉重谷歌上搜索我见过的人后提跨域.xml文件。不完全知道这是什么,但我添加了一个到Web服务器的根目录下运行Silverlight控件的,并添加下面的文本。没有任何区别:

After some heavy googling I've seen people mention a crossdomain.xml file. Not entirely sure what this is but I added one to root directory of the web server running the Silverlight control any and added the following text. didn't make any difference:

<?xml version="1.0" ?>
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>



这是怎么回事?

What's going on?

推荐答案

该crossdomain.xml文件需要放置你想下载从文件,而不是服务于Silverlight应用程序服务器上的服务器上。

The crossdomain.xml file needs to be placed on the server you're trying to download the file from, not on the server that serves the Silverlight application.

如果该服务器没有crossdomain.xml文件,Silverlight运行时不允许应用程序从该服务器下载数据。默认情况下,它只能访问它是从(同源策略)下载的服务器。

If the server doesn't have a crossdomain.xml file, the Silverlight runtime does not allow your application to download data from that server. By default, it can only access the server it was downloaded from (same origin policy).

这篇关于WebClient.DownloadStringAsync在Silverlight抛出安全例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆