ArcGIS RIA Developers: Tips on using cross-domain policies - Part 2 (Troubleshooting)

Part 1 of this series gave you a brief introduction to cross-domain policies, and showed you where to correctly place your policy files. In this post we want to show you some basic troubleshooting techniques for both Adobe Flex and Microsoft Silverlight. If you are having problems such as maps not displaying, or you are getting security sandbox errors then you may be having cross-domain policy problems. Here are some basic guidelines to follow:

  • Make sure the policy file is downloading
  • Make sure you are using the latest policy file
  • Check your policy file settings
  • Examine the error messages
  • Set your project to run on local web server

Note, in this post we are focusing on resources within your domain and sub-domains; for example http://www.yourwebsite.com/ and http://maps.yourwebsite.com/. The cross-domain file needs to be on the machine with the data or service, and not necessarily the machine hosting the Flex (SWC) or Silverlight app (XAP). Also, if you are having problems accessing third party resources, then you'll need to work with the third party directly to figure out their cross-domain policies and procedures. 

Make Sure the Policy File is Downloading

There are a number of easy ways to verify if the policy file is being downloaded to the client. In Firefox click on the “Net” tab in Firebug. Or, if you are using Internet Explorer then Fiddler is a good choice. If you want more details on Firebug and Fiddler there's a short write up in a previous ArcGIS Developer blog post. Silverlight developers should also look at using Silverlight Spy. Silverlight Spy gets the extra bonus points for having a cross-domain access policy validator.

If the client app can find and download the policy file, you should see a "200 OK" message. Another trick is to try and load the URL from a browser window, for example: http://tasks.arcgisonline.com/crossdomain.xml if that's the server you are trying to access content from.  

 

Make Sure You Are Using the Latest Policy File 

When you make changes to the cross-domain file, be sure to refresh/reload the page to make sure the browser "sees" the latest version. If you have tried multiple web page reloads and still see "304 Not Modified", then you have a few options:

  • Manually clear your cache

You can clear your entire cache, although this often isn't very desirable if you have a lot of useful links stored. In Firefox 3.5.x they recognized this problem and implemented a very nice, new feature that lets you remove everything from the last hour called Clear Recent History.

  • Bypass the cache

You can bypass the cache and force the whole page to reload even if there is a cached copy. Here's a page that explains how to do this: http://en.wikipedia.org/wiki/Bypass_your_cache.

Check the Policy File Settings 

Do a little digging into what settings are appropriate for your domain security. A typical default file is completely open and allows access to all your sub-domains from any external domain. This may not meet your organizations security requirements. Adobe's Cross-domain Policy File Specification article has a good discussion on the different configuration options for crossdomain.xml. For Silverlight developers, there is an MSDN article on Network Security and Access Restrictions that talks about the various configuration options in clientaccesspolicy.xml.

Examine the Errors

Most of the time, reading the error carefully will offer some important hints on how to resolve the problem. The really important information will be in the very first line or two of the error message dump. Just as an FYI, Flex has over twenty different errors related to Security sandbox violations. Silverlight 3 has only a handful related specifically to security sandbox violations.

Here are a few of some of the most common problems with hints and suggestions on how you might be able to resolve them:

  • Error #2048: Security Sandbox Violation (Flex only)

Cross-domain policy file is missing, or incorrectly configured to allow access. Check to see if policy file is downloading, and check its settings.

  • An Error occurred while trying to make a request to URI...This could be due to attempting to access a service in a cross-domain way... (Silverlight only)

Cross-domain policy file is missing, or incorrectly configured to allow access. Check to see if policy file is downloading, and check its settings.

  • 404 Not Found (Flex or Silverlight)

File is missing, or in the wrong directory. See Part 1 for suggestions on how to locate the root directory.

  • 404 Not Found - but your policy file is definitely in the right place. (Flex or Silverlight)

A few things could be wrong here. Check your policy file pathname carefully. Copy the URL into a browser to see if it loads the policy file. Check your firewall logs to make sure the request isn't being blocked, especially if its on a non-standard port number, for example: http://subdomain.yourwebsite.com:8001/map.aspx.

  • Error #2032 Stream Error. (Flex only)

The URL is blocked or the policy file wasn't found by URLLoader() or URLRequest(). It can also show up when using HTTPS and HTTPService(). Re-check that your URL is correctly spelled and is loadable. Try to run the app in a browser while using Firebug or Fiddler.  

  • Cross-domain file 200 OK but still get Security Sandbox Violation. (Flex or Silverlight)

The policy file loaded okay, but domain access is not allowed. Check the policy file settings.

  • Cross-domain file 200 OK but getting 500 Internal Server Error. (Flex or Silverlight)

Problem is with the server not the client app. Check directory permissions and other configuration files for your server. On a Windows Server check the Event Viewer log since it will contain all the details for the error.

Set Project to Run on Local Web Server

If you are running into cross-domain problems on your dev box while making calls to external web services, or if you want to more accurately represent a production environment, try setting your Flex Builder or Visual Studio project to run on your local web server (e.g. IIS or Apache).  

Here's an example for Visual Studio 2008 and IIS 7. For Flex, see the example screenshot below. Also don't forget to move your cross-domain policy files to your local web server root.

Additional Resources


 

Published Monday, September 28, 2009 5:46 PM by andygup
Filed under:

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

 

gruner tee said:

Hi, Hey good stuff…keep up the good work! Thanks for the tips.
October 21, 2009 1:47 AM
 

dsi r4 said:

Thanx for the valuable information. This was just the thing I was looking for, keep posting. Will be visiting back soon.
November 3, 2009 3:35 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit