简体   繁体   中英

Why WebClient not displaying web page?

The code below compiles but it does not display the text or photos of the website. I just want to run a program that involves HTTP communication with Silverlight. Any idea why I am not getting the website to display? I just get "error occurred" in the textBlock to display instead

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";
            }
        }
    }
}

It is a crossdomain issue where the xml is not present in the server as a result you are getting the exception

Heres a link where I found the issue you can go through it

Security Exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM