Telerik blogs

I have been part of Telerik’s Silverlight team for almost a year now, and I too well know that our marketing team is just two floors away to say anything bad about marketing.  So I will just say that now having Silverlight 2 in its official version out, marketing mix should adopt one more P in its four P’s concept, Ptechnology. That is why, I will try to explain this topic step by step, so that all marketing guys attracted by the name of this topic can delete the first paragraph and give it to their development teams for consideration.

Since its official release, Silverlight 2 exposes a lot of hot trends and technology techniques as the UI Automation and Accessibility that we were so passionate about lately. Another nice thing about Silverlight is that the server technology and client html technology at runtime are fairly similar to Flash. This topic shows how reasonably easy it is to use cross-domain Silverlight application (xap files) as banner ads hosted on one domain and published onto another. There are certain steps that should be followed in order to integrate existing Silverlight xap file into another website.

1.       Enable Silverlight in the Publisher’s website

2.       Configure the object tag to access cross-domain Silverlight applications

3.       Create access policy to enable cross-domain access

Enable Silverlight in the Publisher’s website

Now, I will have to use two different computers to show you how the cross-domain banner works. I have hosted a simple Silverlight application that consists of Telerik's RadWindow for Silverlight and a simple image banner inside it. The application is called "BannerHost" and is hosted on my IIS server which is currently exposed to the "Publisher" website (http://borisov.telerik.com/BannerHost/ClientBin/BannerAd.xap). The publisher website will access this banner and show it as part of its web content.  Later I will talk about the way access policies are set to enable accessibility to services and resources by Silverlight.  

A prerequisite for those who don’t use IIS 7.0 is to configure their web server to associate .xap files to the MIME Type “application/x-silverlight-app”. To enable Silverlight on our publisher webpage using Visual Studio 2008 you should right click on the webpage and select properties. Then you should add existing Silverlight application in order to enable Silverlight on your existing ASP.NET website. After we have enabled Silverlight on our existing web page we configure our html object tag that hosts the Silverlight application to access a resource on a different domain instead of the local Silverlight application you have just referenced.

The Silverlight object tag looks like this:

<div id="silverlightControlHost">     
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%" />    
    <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>    
 </div>   

 

Configure the object tag to access cross-domain Silverlight applications

In the object tag there are two important parameters that we have to consider when dealing with cross-domain access, these are source and enableHtmlAccess parameters. The source will point to a xap file on the host domain, while the enableHtmlAccess will define whether the hosted content will be able to interact with the HTML DOM. Using the enableHtmlAccess property is essential, because it not only authorizes the hosted application to interact via the HTML DOM using javascript, but also any Click-Thrus won’t occur in case the enableHtmlAccess property is set to false. 

<div id="silverlightControlHost">     
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">     
        <param name="source" value="http://borisov.telerik.com/BannerHost/ClientBin/BannerAd.xap"/>     
        <param name="enableHtmlAccess" value="true" />    
        </object>    
        <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>    
 </div>    
   
 

 

You can also configure the Silverlight application in your aspx webpage by editting the following code.

<asp:Silverlight ID="Xaml1" runat="server"      
    Source="http://borisov.telerik.com/BannerHost/ClientBin/BannerAd.xap"      
    HtmlAccess="Enabled"      
    MinimumVersion="2.0.31005.0"    
    Width="100%" Height="100%" /> 

Now, our "Publisher" website, hosted on http://paskov.telerik.com/ has silverlight enabled and its source is set to our cross-domain resource. PublisherTestPage.aspx is currently blank and consists only of the Silverlight application hosted on http://borisov.telerik.com/.          

 

Create access policy to enable cross-domain access

In order to access all resources in one domain from another you should configure some access policies on the domain in which the Silverlight application is hosted. One way is to create ClientAccessPolicy.xml file and place in the root of the domain for example http://borisov.telerik.com/ClientAccessPolicy.xml. In our case we used the following preconfigured xml file that gave us full access to the resources.

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

 

For security reasons it’s advisable to check the online resources about “Making a service online across domain boundaries” at http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx Moreover, you can check an official guide by Microsoft on the same issue called "Silverlight Advertising Serving Publishing Guide".


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.