Flex調用ASP.NET Web Service時的沙箱問題

來源:互聯網
上載者:User
  今天用Flex調用ASP.NET的Web Service時老是跳出了"Security error accessing url"的錯誤,查了資料,才知道這原來根Flash的沙箱有關。

  原理是,當SWF檔案試圖訪問其它域上的資料時,Flash Player自動載入那個域上的policy檔案,如果SWF檔案所在的域被包含在這個policy檔案中,資料就可以被訪問,否則就不行,以下是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,如果不想麻煩的話,檔案名稱就不要用其它的,就用這個。
把以下內容複寫到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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.