Silverlight使用HttpWebRequest和HttpWebResponse时发生System.Security.SecurityException: 安全性错误

异常代码发生在第二句


HttpWebRequest request = result.AsyncState as HttpWebRequest;

WebResponse response = request.EndGetResponse(result);


提示信息:

System.Security.SecurityException ---> System.Security.SecurityException: 安全性错误。

   位于 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   位于 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   位于 System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   --- 内部异常堆栈跟踪的结尾 ---
   位于 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

   位于 SilverlightApplication2.MainPage.ResponseCallback(IAsyncResult result)


解决:

   在\webapps\ROOT\下增加两个文件:

   crossdomain.xml和clientaccesspolicy.xml

------------------------------------------------------------------------

--crossdomain.xml--

------------------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM " http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all" />
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>


------------------------------------------------------------------------

--clientaccesspolicy.xml--

------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
            <access-policy>
              <cross-domain-access>
                <policy>
                  <allow-from http-request-headers="*">
                    <domain uri="*"/>
                  </allow-from>
                  <grant-to>
                    <resource path="/" include-subpaths="true"/>
                  </grant-to>
                </policy>
              </cross-domain-access>
            </access-policy>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值