I am writing a small silverlight application to try silverlight. My idea is to make a small application that checks if websites are on the Internet. It works from the user entering the URL, and my application checks its operation every 5 minutes.
But when I ever make a web request, I get a security exception below. A reading of http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.95).aspx seems to indicate that silverlight does not allow cross-domain connections. So there is no way to get my idea to work in Silverlight?
Code example:
WebRequest testHTTP = null; try { testHTTP = WebRequest.Create(serverToCheck); } catch (UriFormatException ufe) { try { testHTTP = WebRequest.Create("http://" + serverToCheck); } catch (UriFormatException ufe1) { MessageBox.Show("Invalid server address"); } } if (testHTTP != null) { testHTTP.BeginGetResponse(new AsyncCallback(doCheck), testHTTP); } void doCheck(IAsyncResult a) { try { HttpWebRequest req = (HttpWebRequest)a.AsyncState; HttpWebResponse res = (HttpWebResponse)req.EndGetResponse(a); Dispatcher.BeginInvoke(() => HTTPStatus.Content = "OK"); } catch (Exception ex) {
Exception: {System.Security.SecurityException ---> System.Security.SecurityException: security error. in System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse (IAsyncResult asyncResult) in System.Net.Browser.BrowserHttpWebRequest. <> c__DisplayClass5.b__4 (Object sendState) in System.Net.Browser.AsyncHelper. <> c__DisplayClass2.b__0 (Object sendState) --- The end of the internal check of the exception stack --- in System.Net.Browser.AsyncHelper.BeginOnUI (SendOrPostCallback beginMethod, object state) in System.Net.Browser.BrowserHttpWebRequest.EndGetResponseessecsynsrssultsultesultesynessultsynsrcultsynsesultsultsynsrssultsultsultsynssyncultsultsynsultsynsrssultsultsultsultsultsultsultesultesultesultesultesultsynsr ) on the monitor .Home.doCheck (IAsyncResult a)}
source share