SilverLight, for security reasons, restricts access to URLs by default, allowing access only to URL resources under the same subdomain.
The following table lists the URL access rules in Silverlight 2.0:
|
webclient object |
Media , images, ASX |
XAML file, Font file |
streaming media |
allowed Protocols |
HTTP, HTTPS | Td>http, HTTPS, file
http, https, file |
http |
Cross-protocol access |
not allowed |
not allowed |
not allowed |
do not allow access from HTTPS |
cross-web domain access |
not allowed |
allow |
do not allow |
allow |
if not from HTTPS
Cross Security Zone access (Windows) |
does not allow |
do not allow |
do not allow |
do not allow |
Cross Security Zone access (Macintosh) |
does not allow |
allow |
do not allow |
allow |
allow redirection |
same domain allow |
allow |
same domain allow |
do not allow |
If WCF is not at the same site as the Silverlight Web, then we are going to put two XML files on the root domain of the accessed side Clientaccesspolicy.xml,crossdomain.xml
If you want to access resources from another site through webclinet, you need to put the domain Access policy XML file on the visited site, or the event arguments inside the complete event will report an empty object reference. This problem has plagued me for a long time, now finally solved, put up to share with you.
For specific instructions on Clientaccesspolicy.xml,crossdomain.xml, please refer to MSDN http://msdn.microsoft.com/en-us/library/cc645032 (vs.95) . aspx
These days want to use Silverlight to access the Web site XML file, as well as cross-domain use session information, has been prompted security errors, search a lot, and finally solved.
To add a ClientAccessPolicy.xml file at the site root, the code is as follows:
<?xml version="1.0"encoding="Utf-8"?><access-policy> <cross-domain-access> <policy> <allow- fromhttp-request-headers="*"> <domain uri="*"/> </allow- from> <grant-to> <resource include-subpaths="true"Path="/interface"/> </grant-to> </policy> </cross-domain-access></access-policy>
Where/interface is the path to the file that needs to be accessed, and the file needs to be placed in the root directory of the site that will be accessed.
I see a lot of include-subpaths= "false" written on the Internet. I tried, seemingly not, and do not know what the reason.
More resources:
Http://silverlightchina.net/html/tips/2009/0916/184.html
Http://silverlightchina.net/html/tips/2010/0107/563.html
This Microsoft detailed description:
http://msdn.microsoft.com/zh-cn/library/cc645032 (v=vs.95). aspx
URL resource cross-domain access cross-domain use session information