別の Web サイトからテキスト ファイルを読み込む必要がある Silverlight 5 プロジェクトがあります。「他の」Web サイトに clientaccesspolicy.xml ファイルをインストールしました。
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*" />
</allow-from>
<grant_to>
<resource path=/public_html/services/" include-subpaths="true"
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
このファイルは、Linux ベースの Web サイトである「その他」の Web サイトのルート ディレクトリにあります。(そこの public_html ディレクトリにも入れてみました。)
私のコードにはこれがあります:
var uri = "http://www.otherwebsite.com/services/TextFile.txt";
var webClient = new WebClient( );
webClient.OpenReadCompleted += ( s, e ) =>
{
using ( var stream = new StreamReader( e.Result ) )
{
// stream processing logic
}
};
webClient.OpenReadAsync( new Uri( uri, UriKind.Absolute ) );
「new StreamReader」ステートメントの OpenReadCompleted デリゲートで System.Security.SecurityException を取得します。
ブラウザで明示的にファイルに移動すると、ファイルにアクセスできることを確認できます。私は Silverlight を初めて使用し、Web の第一人者ではないため、おそらく間違っていることがたくさんあります。