ArcGIS RIA Developers: Tips on using cross-domain policy files - Part 1 (Intro)

If you have spent any time with Adobe Flex or Microsoft Silverlight, there is an excellent chance you have encountered errors such as “Security sandbox violation:”, or “An error occurred while trying to make a request to URI”. Or maybe you had problems where a map layer or certain Graphic images weren't displaying. If you've hit one of these problems while trying to access your own content or services, it's possible there is something wrong with your cross-domain policy file. There's been alot of discussion on this topic in the ESRI forums and elsewhere on the internet, that's why we wanted to shine some light on a few key things to know.

In Part 1 of this series, we give you a brief introduction to these types of files, provide a few example use cases, and show you how to make sure they have been placed in the right location on your web server.

What is a cross-domain policy file?

As a general rule, if your web application requests files and resources from the same origin (e.g. your domain name, port number and http protocol), then access is granted automatically. If you want to allow client apps to request resources from within your domain, but outside the origin, then you'll need a cross-domain policy file. The file also determines which external domains are granted accesss to your web server. Examples of the types of resources you might want to grant access to include map services, geoprocessing services or GeoRSS. Cross-domain policy files also eliminate the need for your users to implement a proxy in order to access your website content.

Before Flex or Silverlight apps will allow a connection to a web resource, the runtime attempts to download the cross domain policy file from the web server. If one can’t be found, or there is a problem reading the file, then the runtime denies access and throws an error.  Silverlight uses a file named clientaccesspolicy.xml, and if your Silverlight app doesn’t find one it will then search for crossdomain.xml. Flash, on the other hand, only uses crossdomain.xml.

Here’s an example of a clientaccesspolicy.xml and crossdomain.xml.

What are my choices if I'm using JavaScript? 

Even though this post is about Flex and Silverlight, we still wanted to mention JavaScript briefly. If you are using the ArcGIS API for JavaScript, or the Google or Virtual Earth (Bing) Extensions, then you won't be able to use a cross-domain policy file. Here's a good basic primer by the Yahoo! Developer Network folks on using JavaScript proxies, and the SitePen blog has several posts on Dojo and cross-domain access:

What are some example use cases? 

The following example is from within the same origin. Maps.swf is requesting image tiles from the same origin. This does not require a cross-domain policy file:

     Application host location: http://www.yourwebsite.com/maps.swf
     Map tile location: http://www.yourwebsite.com/images/tiles1.jpg

And, here is an example that does require a cross-domain policy file. Your application is requesting a GeoRSS file from a sub-domain on your website:

     Application host location: http://www.yourwebsite.com/maps.swf
     GeoRSS file location:http://georss.yourwebsite.com/weather     
     Location of policy file: http://georss.yourwebsite.com/crossdomain.xml

Or, you're testing your app in Visual Studio, and it's trying to access your Bing geocoder token file which is on a test web server:

     Application host location:  http://localhost:3782/maps.aspx
     Bing Proxy file location: http://testserver/vetoken.ashx
     Location of policy file: http://testserver/clientaccesspolicy.xml  

Your application is accessing a REST endpoint that exists on a different domain:

     Application host location: http://www.yourwebsite.com/maps.aspx
     ArcGIS Server REST endpoint: http://www.someotherwebsite.com/ArcGIS/rest/services/Streets/MapServer
     Location of policy file: http://www.someotherwebsite.com/clientaccesspolicy.xml

Adobe’s Flash Player 10 Security Whitepaper also notes the following about HTTPS, “By default, content loaded with a protocol other than HTTPS cannot access content that was loaded with HTTPS, even if from the same domain. The reverse direction is allowed; HTTPS content may access content loaded with other protocols from the same domain”.

Where do I place my cross-domain policy file?

In the majority of cases where there are problems with cross-domain access, you are most likely missing a cross domain policy file, or it may simply be located in the wrong directory. If you are just getting started, we recommend placing the file in its' default location: your web server's root directory. Included below is a screenshot showing the right location for these files on a Windows web server. If the file is placed incorrectly, such as in your application's directory, you will get errors when trying to access content.

 

How do I figure out where my root directory is?

In IIS 5 and 6:

  • On the Start menu, click Run.
  • In the Open dialog box, type inetmgr, and then click OK.
  • Right click on Default Web Site, select Properties.
  •  Select Home Directory tab, and look under Local Path.

 

In Apache 2.2.x search for httpd.conf. Or if you are using Windows:

  • Go to Start, select All Programs
  • Click on Apache HTTP Server 2.2.x
  • Click on Configure Apache Server
  • Click on Edit the Apache httpd.conf Configuration File 
  • Search for "DocumentRoot"

That's it for Part 1. Stay tuned to this blog for Part 2.

Information Resources


Published Thursday, September 10, 2009 10:30 AM by andygup

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Dave said:

The first bullet point link for the JavaScript proxy does not work.
September 10, 2009 10:54 AM
 

andygup said:

Thanks...should be fixed now.
September 10, 2009 11:08 AM
 

diligentpig said:

Silverlight 3 – Network Security and Access Restrictions (MSDN) link does not work neither.
September 13, 2009 12:34 AM
 

andygup said:

Should be fixed. Apparently I'm batting 0.00 on the links.
September 14, 2009 9:51 AM
 

organized_chaos said:

These are good but here is a link to placement inside jboss http://forums.esri.com/Thread.asp?c=158&f=2421&t=291194#910177
September 29, 2009 11:38 AM
 

fit flops said:

Thank you for another great post. I look forward to many more entries with high quality info. Keep posting.
fit flops
November 2, 2009 12:53 AM
 

r4 said:

Is it possible to add new references to cross-domains at run-time? Let's say I want somebody to enroll and give me their domain name before I allow them to use my silverlight app. If I took that domain and added it the cross-domain xml file would that change occur without a compile or IIS reset?

November 8, 2009 11:46 PM
 

andygup said:

You should be able to manually modify cross-domain at run-time. Only the URL to the cross-domain file is compiled into the SWF. If someone's already visited your site, then there's a chance their browser won't recache the new file right away. Also, if you have an on-line enrollment page and you've locked down your site via cross-domain, how will they access your site to enroll?

November 9, 2009 8:27 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit