今天用Flex調(diào)用ASP.NET的Web Service時老是跳出了"Security error accessing url"的錯誤,查了資料,才知道這原來根Flash的沙箱有關(guān)。
原理是,當SWF文件試圖訪問其它域上的數(shù)據(jù)時,F(xiàn)lash Player自動加載那個域上的policy文件,如果SWF文件所在的域被包含在這個policy文件中,數(shù)據(jù)就可以被訪問,否則就不行,以下是Adobe官方的原文:
When a SWF file attempts to access data from another domain,
Flash Player automatically attempts to load a policy file from that domain. If the domain of the SWF file that is attempting to access the data is included in the policy file, the data is automatically accessible.
而我所碰到的問題,就是因為我的IIS上沒有這個policy file,那解決辦法自然就是加上這個policy file。
解決辦法:
新建一個xml文件,命名為crossdomain.xml,如果不想麻煩的話,文件名就不要用其它的,就用這個。
把以下內(nèi)容復制到xml文件中:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
然后把它保存到wwwroot下面,我曾試著把它放到應用程序的根目錄,但不起作用,放到wwwroot下是可以的,上述的crossdomail.xml 允許所有的swf文件訪問本主機。
然后就OK了。如果想看更詳細的,就看:
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=05B_Security_176_04.html
Tag標簽: flex,web service,asp.net