Cross-origin access using Silverlight and several common solutions

Source: Internet
Author: User

The cross-origin issue is discovered only when errors occur during Silverlight access to JSON data. Therefore, we sorted out some of the content and listed it.

By default, Silverlight imposes strict restrictions on URL access to ensure security. It only allows access to URL resources in the same subdomain.

The following table lists URL access rules in Silverlight 2.0:

  WebClient object Media, images, ASX XAML files and font files Streaming Media
Protocols allowed HTTP and https HTTP, https, file HTTP, https, file HTTP
Cross-protocol access Not Allowed Not Allowed Not Allowed Access from HTTPS is not allowed
Cross-web domain access Not Allowed If it is not from https, allow Not Allowed Allow
Cross-security region access (Windows) Not Allowed Not Allowed Not Allowed Not Allowed
Cross-security region access (Macintosh) Not Allowed Allow Not Allowed Allow
Redirect allowed Same Domain Allowed Allow Same Domain Allowed Not Allowed

If WCF and Silverlight web are not on the same site, we need to put two XML files clientaccesspolicy. xml and crossdomain. XML in the root domain of the accessed end.
If you want to access the resources of another site through webclinet, you need to put the domain access policy XML file on the accessed site. Otherwise, the event parameter report in the complete event contains a null object reference.

The format of the clientaccesspolicy. xml file should not be set to UTF-8; otherwise, errors may occur easily.

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

Crossdomain. the XML format is very simple. Its root node is <cross-domain-Policy>, which contains one or more <allow-access-from> nodes, <allow-access-from> there is an attribute domain with a value of the allowed domain, which can be the exact IP address, an exact domain, or a wildcard domain (any domain ). Below are two examples:

Program code
<? XML version = "1.0"?>
<Cross-domain-Policy>
<Allow-access-from domain = "http://www.lishewen.com.cn/"/>
<Allow-access-from domain = "* .lishewen.com.cn"/>
<Allow-access-from domain = "222.217.221.16"/>
</Cross-Domain-Policy>

Program code
<? XML version = "1.0"?>
<Cross-domain-Policy>
<Allow-access-from domain = "*"/>
</Cross-Domain-Policy>

The second example allows access to any domain. We recommend that you store the crossdomain. xml file in the root directory of the site!

Such as: http://bbs.lishewen.com.cn/crossdomain.xml

Here I also got an example of Silverlight to test

Http://silverlight.lishewen.net.cn/SyndicationFeedReader/

For more information about clientaccesspolicy. xml and crossdomain. XML, see msdn http://msdn.microsoft.com/en-us/library/cc645032 (vs.95). aspx.

Documents from: http://www.cnblogs.com/format/articles/1282203.html

Http://blog.lishewen.com.cn/post/2008/06/e4bdbfe794a8crossdomainxmle8aea9Silverlighte58fafe4bba5e8b7a8e59f9fe4bca0e8be93e695b0e68dae.aspx

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.