Silverlight cross-domain, Silverlight deployment in IIS and other issues addressed

Source: Internet
Author: User
Tags iis web services silverlight
    

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 to put the cross-domain policy files.

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

clientaccesspolicy.xml Configuration:

<?xmlversion= "1.0" encoding= "Utf-8"?>

<access-policy>

<cross-domain-access>

<policy>

<allow-from>

<domainuri= "*"/>

</allow-from>

<grant-to>

<resourcepath= "/" include-subpaths= "true"/>

</grant-to>

</policy>

</cross-domain-access>

</access-policy>

crossdomain.xml Configuration:

<?xmlversion= "1.0"?>

<cross-domain-policy>

<allow-access-fromdomain= "*"/>

</cross-domain-policy>

two: Silverlight in IIS Deployment

Programs developed with Silverlight, deployed to IIS, will often pop up "Sys.InvalidOperationException:InitializeError error #2104 in control ' XAML1 ': unable to download Silverlight Application. 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.

Add the MIME type to IIS, as shown in the figure:

Three: Silverlight Dynamic binding picture

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>" 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
Ten productlist productlist = Jsonserializer.readobject (responsestream) as productlist;
One new Thread (() =
12 {
Mygrid. Dispatcher.begininvoke (
() =
15 {
Mygrid. DataContext = Productlist.products[0];
The binding binding = new binding ("Productimage");
Rect. SetBinding (image.sourceproperty, binding);
19}
20); }). Start ();
21}
22}

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.