为什么WebClient不显示网页?

时间:2013-09-16 05:54:25

标签: c# asp.net .net silverlight

以下代码编译但不显示网站的文字或照片。我只想运行一个涉及与Silverlight进行HTTP通信的程序。知道为什么我没有让网站显示?我只是在textBlock中出现“错误发生”而不是显示

namespace SilverlightApplication4
{
    public partial class MainPage : UserControl
    {
        string baseUri = "http://yahoo.com";
        WebClient client = new WebClient();            

        public MainPage()
        {
            InitializeComponent();
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);        
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            client.DownloadStringAsync(new Uri(baseUri));
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
                textBox.Text = "Using WebClient: "+  e.Result;
            else
            {
                textBox.Text = e.Error.Message;
                textBlock.Text = "error occurred";
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

这是一个跨域问题,其中xml不存在于服务器中,因此您将获得异常

这是一个链接,我发现了你可以通过它的问题

Security Exception