Programming with .NET - Generalhttp://forums.silverlight.net//17.aspx/1?Programming+with+NET+GeneralGeneral discussions around authoring Silverlight .NET applications.Mon, 01 Jan 0001 00:00:00 -05001734760http://forums.silverlight.net//p/10944/34760.aspx/1?Problem+with+Cross+Domain+accessProblem with Cross-Domain access <p>I'm trying to use Silverlight to access data that is sourced by a mod_python module on an Apache server.</p> <pre class="code">string requestUriString = string.Format(&quot;http://127.0.0.1:80/ord-svg/ordData.py/GetDataOnChange?unitId=X05&amp;basetime={0}&quot;, &#43;&#43;requestId); Uri requestUri = new Uri(requestUriString); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri); request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);</pre> <p>I'm getting a &quot;System.Security.SecurityException: Security error.&quot; exception, which I assume because it is cross-domain.</p> <p>I have a clientaccesspolicy.xml file at the root of http://127.0.0.1:80. If I use IE7 to browse to http://127.0.0.1:80/clientaccesspolicy.xml and View Source, I get</p> <pre class="code">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;access-policy&gt; &lt;cross-domain-access&gt; &lt;policy&gt; &lt;allow-from&gt; &lt;domain uri=&quot;*&quot;/&gt; &lt;/allow-from&gt; &lt;grant-to&gt; &lt;resource path=&quot;/&quot; include-subpaths=&quot;true&quot;/&gt; &lt;/grant-to&gt; &lt;/policy&gt; &lt;/cross-domain-access&gt; &lt;/access-policy&gt;</pre> <p>But my Apache access logs don't show any attempt to retrieve that file before the Security Error is thrown when I run my Silverlight app in VS2008.</p> <p>I'd appreciate any help.&nbsp;What am I missing?</p> 2008-03-07T17:54:34-05:0034765http://forums.silverlight.net//p/10944/34765.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>Are you using a proxy server in your browser settings?</p> <p>Have you tried a Flash crossdomain.xml ?:</p> <p><span class="kwrd"><font color="#0000ff">&lt;?</font></span><span class="html"><font color="#800000">xml</font></span> <span class="attr"><font color="#ff0000">version</font></span><span class="kwrd"><font color="#0000ff">=&quot;1.0&quot;</font></span>?<font color="#0000ff"><span class="kwrd">&gt;</span><br> <span class="kwrd">&lt;!</span></font><span class="html"><font color="#800000">DOCTYPE</font></span> <span class="attr"><font color="#ff0000">cross-domain-policy</font></span>&nbsp;<span class="attr"><font color="#ff0000">SYSTEM</font></span> <font color="#0000ff"><span class="kwrd">&quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;</span><span class="kwrd">&gt;</span><br> <span class="kwrd">&lt;</span></font><span class="html"><font color="#800000">cross-domain-policy</font></span><font color="#0000ff"><span class="kwrd">&gt;</span><br> </font>&nbsp; <span class="kwrd"><font color="#0000ff">&lt;</font></span><span class="html"><font color="#800000">allow-access-from</font></span> <span class="attr"><font color="#ff0000">domain</font></span><span class="kwrd"><font color="#0000ff">=&quot;*&quot;</font></span> <font color="#0000ff"><span class="kwrd">/&gt;</span><br> <span class="kwrd">&lt;/</span></font><span class="html"><font color="#800000">cross-domain-policy</font></span><span class="kwrd"><font color="#0000ff">&gt;</font></span></p> 2008-03-07T18:02:22-05:0034781http://forums.silverlight.net//p/10944/34781.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>I hadn't, because I wanted to eventually edit the &quot;grant-to&quot; section.&nbsp;&nbsp; But I gave it a try just now and it didn't help.&nbsp;&nbsp; The Apache logs just don't show any attempt by the Silverlight app to access the site at all.&nbsp; Neither for clientaccesspolicy.xml nor for crossdomain.xml.</p> 2008-03-07T18:54:34-05:0034786http://forums.silverlight.net//p/10944/34786.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>I've noticed that when the cross-domain policy file is missing I don't get an exception but rather the HttpResponse instance has a StatusCode set to HttpStatusCode.NotFound in the callback.</p> <p>I do recall though that I got some form of security exception when I tried to access the web and my test web page was being served off disk and not from a web project. Could that be the issue?<br> </p> 2008-03-07T19:03:00-05:0034787http://forums.silverlight.net//p/10944/34787.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>The traceback looks like this...</p> <pre class="code">System.Security.SecurityException: Security error. at MS.Internal.InternalWebRequest.Send() at System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) ... </pre> 2008-03-07T19:03:55-05:0034792http://forums.silverlight.net//p/10944/34792.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p></p> <blockquote><span class="icon-blockquote"></span> <h4>CraigN</h4> I do recall though that I got some form of security exception when I tried to access the web and my test web page was being served off disk and not from a web project. Could that be the issue?<br> </blockquote> <p></p> <p>Very likely that is the issue.&nbsp;&nbsp; I see that VS2008 is now (Silverlight 2.0b1) serving the page off disk.&nbsp;&nbsp; Before (Silverlight 1.1a) it seemed to start a server on some arbitary port and to run my web app from there.&nbsp;&nbsp; Is that kind of behavior still available?</p> <p>&nbsp;</p> 2008-03-07T19:13:43-05:0034794http://forums.silverlight.net//p/10944/34794.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>I can see where the exception is thrown in the code, its in response to a System.UnauthorizedAccessException being thrown when trying to execute the native windows method. Is the site possibly not in a trusted browser zone or something?<br> </p> 2008-03-07T19:18:15-05:0034797http://forums.silverlight.net//p/10944/34797.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p></p> <blockquote><span class="icon-blockquote"></span> <h4>shacktoms</h4> I see that VS2008 is now (Silverlight 2.0b1) serving the page off disk.&nbsp;&nbsp; Before (Silverlight 1.1a) it seemed to start a server on some arbitary port and to run my web app from there.&nbsp;&nbsp; Is that kind of behavior still available?</blockquote> &nbsp; <p></p> <p>Yeah still available and the default way of doing things if you use the new wizard to create a Silverlight Application. Simply create a new or use an existing Web Application Project (my preferred project type) or a Web Site project and use the &quot;Add Silverlight Link&quot; functionality to do the same thing. It should create an HTML test page and I believe an ASPX one as well.<br> &nbsp;</p> 2008-03-07T19:22:52-05:0034803http://forums.silverlight.net//p/10944/34803.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>That solved the problem.&nbsp; The access doesn't even seem to considered cross-domain.&nbsp; Thanks, CraigN.</p> 2008-03-07T19:36:57-05:0034804http://forums.silverlight.net//p/10944/34804.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access My pleasure, glad I could help. Its an odd one, but most likely well justified as most security exceptions.<br> 2008-03-07T19:43:22-05:0036958http://forums.silverlight.net//p/10944/36958.aspx/1?Re+Problem+with+Cross+Domain+accessRe: Problem with Cross-Domain access <p>I am running into the same issue and getting &quot;security error&quot;. I have created a web app and this is running on my localhost. When i try to invoke a service on&nbsp;a different domain using HTTPWebrequest or webclient, i get the &quot;Security Error&quot;. I checked for calls using Fiddler2 and the call isn't even made to my apache server (hosting the service). </p> <p>I have also added the crossdomain.xml and clientaccesspolicy.xml on the root of my server hosting the service. </p> <p>If i use proxy generated classes against my wsdl on the server, i get a &quot;CrossDomainError&quot;. </p> <p>please suggest what could be going on.&nbsp; Is there some setting in IIS that could be preventing this call?</p> <p>BTW. I am running Silverlight 2 Beta 1 with vs2008</p> <p>&nbsp;</p> 2008-03-14T00:58:52-04:0037125http://forums.silverlight.net//p/10944/37125.aspx/1?Re+Re+Problem+with+Cross+Domain+accessRe: Re: Problem with Cross-Domain access <p>I got this working once i added both localhost and the site that hosted my webservices to trusted zone.</p> 2008-03-14T12:54:15-04:00