Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Problem with Cross-Domain access RSS

11 replies

Last post Mar 14, 2008 12:54 PM by SShankar

(0)
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Problem with Cross-Domain access

    Mar 07, 2008 05:54 PM | LINK

    I'm trying to use Silverlight to access data that is sourced by a mod_python module on an Apache server.

    string requestUriString =
        string.Format("http://127.0.0.1:80/ord-svg/ordData.py/GetDataOnChange?unitId=X05&basetime={0}", ++requestId);
    Uri requestUri = new Uri(requestUriString);
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
    request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);

    I'm getting a "System.Security.SecurityException: Security error." exception, which I assume because it is cross-domain.

    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

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from>
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

    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.

    I'd appreciate any help. What am I missing?

  • robhouweling

    robhouweling

    Contributor

    3308 Points

    565 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 06:02 PM | LINK

    Are you using a proxy server in your browser settings?

    Have you tried a Flash crossdomain.xml ?:

    <?xml version="1.0"?>
    <!
    DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    <
    cross-domain-policy>
      <allow-access-from domain="*" />
    </
    cross-domain-policy>

    (If this has answered your question, please click on mark as answer on this post)



    Cheers!

    Rob Houweling





    My blog
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 06:54 PM | LINK

    I hadn't, because I wanted to eventually edit the "grant-to" section.   But I gave it a try just now and it didn't help.   The Apache logs just don't show any attempt by the Silverlight app to access the site at all.  Neither for clientaccesspolicy.xml nor for crossdomain.xml.

  • CraigN

    CraigN

    Member

    352 Points

    89 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:03 PM | LINK

    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.

    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?

    Microsoft Xbox MVP
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:03 PM | LINK

    The traceback looks like this...

    System.Security.SecurityException: Security error.
       at MS.Internal.InternalWebRequest.Send()
       at System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
       ...
    
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:13 PM | LINK

    CraigN

    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?

    Very likely that is the issue.   I see that VS2008 is now (Silverlight 2.0b1) serving the page off disk.   Before (Silverlight 1.1a) it seemed to start a server on some arbitary port and to run my web app from there.   Is that kind of behavior still available?

     

  • CraigN

    CraigN

    Member

    352 Points

    89 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:18 PM | LINK

    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?

    Microsoft Xbox MVP
  • CraigN

    CraigN

    Member

    352 Points

    89 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:22 PM | LINK

    shacktoms

    I see that VS2008 is now (Silverlight 2.0b1) serving the page off disk.   Before (Silverlight 1.1a) it seemed to start a server on some arbitary port and to run my web app from there.   Is that kind of behavior still available?
     

    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 "Add Silverlight Link" functionality to do the same thing. It should create an HTML test page and I believe an ASPX one as well.
     

    Microsoft Xbox MVP
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:36 PM | LINK

    That solved the problem.  The access doesn't even seem to considered cross-domain.  Thanks, CraigN.

  • CraigN

    CraigN

    Member

    352 Points

    89 Posts

    Re: Problem with Cross-Domain access

    Mar 07, 2008 07:43 PM | LINK

    My pleasure, glad I could help. Its an odd one, but most likely well justified as most security exceptions.
    Microsoft Xbox MVP