I am trying to write a function in my Silverlight application that requests a specific page that does not exist in the same domain where my Silverlight application is hosted.
For instance:
However, this throws a "SecurityException":
{System.Security.SecurityException: Security Error. in System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse (IAsyncResult asyncResult) in System.Net.Browser.ClientHttpWebRequest.EndGetResponse (IAsyncResult asyncResult) ...}
From what I understand, this is due to the fact that cross-domain requests are limited, and found some posts that mentioned this article (http://msdn.microsoft.com/en-us/library/cc197955(VS. 95) .aspx) may be related.
Here is my code:
public static void CheckPageContentsAsync(CheckPageContentsCallback callback, DependencyObject uiObject) { bool result = false; try { HttpWebRequest request = WebRequest.CreateHttp("http://www.mysite.com/MyPage.aspx"); request.BeginGetResponse((asyncHandle) => { try { uiObject.Dispatcher.BeginInvoke(new VoidDelegate(() => { HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncHandle); using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string content = sr.ReadToEnd(); if (content.Contains("Value")) { result = true; } if (callback != null) { callback.Invoke(result); } } }), null); } catch (Exception excep) { throw new Exception("Failed to process response.", excep); } }, null); } catch(Exception excep2) { throw new Exception("Failed to generate request.", excep2); } }
It was not possible to fully understand the applicability of the files "clientaccesspolicy.xml" or "crossdomain.xml" as a solution.
Can someone explain how I can change my application or the web server I am requesting to solve this problem?
source share