"Go" Silverlight cross-domain access

Source: Internet
Author: User
Tags silverlight

MIDI Source: Blog Park Published: 2010-01-01 17:39 read: 204 times original link[Collection]   when Silverlight uses WebService, WCF, WebRequest, etc. for data communication, it is often necessary to face cross-domain access issues. Silverlight 2 Beta 1 provides support for team cross-domain access and supports crossdomain.xml policy files like Flash. On the Internet to check some relevant information, found that the policy file content is as follows:

<?xml version= "1.0"?>
<cross-domain-policy>
<!--Http://192.168.0.1/crossdomain.xml--
<allow-access-from domain= "www.aaa.com"/>
<allow-access-from domain= "*.bbb.com"/>
<allow-access-from domain= "192.168.1.1"/>
</cross-domain-policy>
The example above indicates that Silverlight from Www.aaa.com, *.bbb.com, 192.168.1.1 is allowed to access native data (Ftp,http,https mode) across domains.
If you need to allow Silverlight from any domain to access native data, the file contents are as follows:

<?xml version= "1.0"?>
<!--Http://localhost/crossdomain.xml--
<cross-domain-policy>
<allow-access-from domain= "*"/>
</cross-domain-policy>

After you have written the above files, copy the files to the root site of the server.

----------

One: Silverlight cross-Domain

Silverlight has done a lot of thinking about network security when it comes to design, depending on the Silverlight SDK.

Cross-domain communication is a Web service that uses the correct cross-domain policy file in the root deployment of another domain to enable Silverlight-based applications to invoke Web services in that domain. Silverlight supports two types of cross-domain policy files.

·  Silverlight Cross-Domain Policy (clientaccesspolicy.xml)

·  A subset of Flash cross-domain policies (crossdomain.xml)

Cross-domain communication using cross-domain policy files

Typically, if a Silverlight-based application detects that its request is a cross-domain request, the Silverlight cross-domain Policy file (clientaccesspolicy.xml) is first located at the application root of the Web service. If this request results in a "404 Not Found" or other error, the application looks for the Flash cross-domain Policy file (crossdomain.xml) at the root of the application. Redirection of cross-domain policy files is not allowed. Additionally, the cross-domain policy file remains valid for the application session.
Now you know. As long as you deploy a cross-domain policy file in your Web site, you can resolve Silverlight cross-domain request issues. Where do the cross-domain policy files go?

Note: cross-domain Policy files must also be placed in the root directory only on the site.

clientaccesspolicy.xml configuration :

<?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>

Crossdomain.xml Configuration:

<?xml version= "1.0"?>

<cross-domain-policy>

<allow-access-from domain= "*"/>

</cross-domain-policy>

Two: Silverlight in the IIS Deployment

programs developed with Silverlight, deployed to IIS, will often pop up "Sys.InvalidOperationException:InitializeError error #2104 in control ' XAML1 ': The Silverlight application could not be downloaded. Please review the WEB server settings exception.

The reason for this exception: the XAP in the Silverlight program ClientBin directory and files with XAML suffix names are not recognized by IIS requests.

Workaround: In IIS, add the MIME type.

MIME type
. xaml Application/xaml+xml
. xap Application/x-silverlight-app

If you still have a problem, check the configuration of IE, and let go of the XAML Active download option in security.

To add a MIME type to IIS:

Three: Silverlight dynamically bound Pictures

when the asynchronous request data is dynamically bound with the image tag, the "Sys.InvalidOperationException:ImageError error #4001 in control ' Xaml1" occurs every time the page reloads: ag_ E_network_error "Exception.

The image tag is bound in the following form:

<image x:name= "rect" stretch= "Fill" canvas.left= "" "canvas.top=" "" source= "{Binding productimage}" </image >

The reason for this exception: binding occurs before setting DataContext, so the image path is not set to the value you expect, so the source path of the image tag is not available at this time.

Modify the method code as follows:

Remove source= "{Binding productimage}" in XAML, DataContext bind the data, and then set the binding value on the image tag. For example:

<image x:name= "rect" stretch= "Fill" canvas.left= "canvas.top=" </Image>

View Plaincopy to Clipboardprint?
  1. private void Responseready (IAsyncResult asyncResult)
  2. {
  3. WebRequest request = asyncresult.asyncstate as WebRequest;
  4. WebResponse response = Request. EndGetResponse (AsyncResult);
  5. using (Stream Responsestream = response. GetResponseStream ())
  6. {
  7. DataContractJsonSerializer Jsonserializer =
  8. New DataContractJsonSerializer (typeof (ProductList));
  9. ProductList productlist = Jsonserializer.readobject (responsestream) as productlist;
  10. New Thread (() =
  11. {
  12. Mygrid. Dispatcher.begininvoke (
  13. () =
  14. {
  15. Mygrid. DataContext = Productlist.products[0];
  16. Binding binding = new binding ("Productimage");
  17. Rect. SetBinding (image.sourceproperty, binding);
  18. }
  19. ); }). Start ();
  20. }
  21. }

"Go" Silverlight cross-domain access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.