Silverlight SecurityException

时间:2010-11-17 20:52:30

标签: silverlight-4.0 securityexception

我正在将数据发布到服务器并成功执行BeginGetRequestStream,然后是EndGetRequestStream,将我的POST数据写入填充RequestStream,并调用BeginGetResponse。

BeginGetResponse成功返回,然后我调用:

Dim response As HttpWebResponse = CType(MyHttpRequest.EndGetResponse(asynchronousResult), HttpWebResponse)

此行抛出以下SecurityException错误:

  

{System.Security.SecurityException ---> System.Security.SecurityException:安全错误。
  在System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
  在System.Net.Browser.BrowserHttpWebRequest。<> c__DisplayClass5.b__4(Object sendState)
  在System.Net.Browser.AsyncHelper。<> c__DisplayClass2.b__0(Object sendState)

     

---内部异常堆栈跟踪结束---
  在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,Object state)
  在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
  在EtsyV2NetSL.WebQuery.POST_ResponseCallback(IAsyncResult asynchronousResult)}

所以我的第一个想法是我被服务器用clientaccesspolicy.xml或crossdomain.xml阻止了。我已经解雇了Fiddler并看到了以下内容:

GET http://openapi.etsy.com/clientaccesspolicy.xml > 596 (text/xml)
GET http://openapi.etsy.com/crossdomain.xml > 200 OK (application/xml)

所以我检查了他们的crossdomain.xml,设置显示正常:

<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <allow-access-from domain="*"/>
</cross-domain-policy>

我试图解决这个问题已经走到了尽头。我在VS的开发机器上运行测试应用程序。

有没有人想知道为什么Silverlight会抛出这个错误?

由于

2 个答案:

答案 0 :(得分:1)

我今天处理了一个非常类似的问题 - 但是我试图进行WCF服务调用而不是HTTP POST。

以下是我在我的代码中发表的评论 - 如果不清楚有用,请告诉我。

// NB: Cross-domain bug
// If you end up here with a System.Security.SecurityException "Security error."
// Check that you're not trying to cross zones when making a service call
// (eg: Accessing Trigger Driver TimeSource service on http://IASWEB01/ when accessing the site via usertest.local
//  or any other URI with dots in it - yes it seems crazy)

这似乎是一些安全'功能'。通过WCF调用,我甚至在Silverlight客户端尝试从目标主机获取clientaccesspolicy.xml之前就遇到了此异常。在没有真正解决方案的情况下非常恼人的问题!

答案 1 :(得分:1)

看起来这是客户端访问策略问题,请查看:

http://forums.silverlight.net/forums/p/26566/90867.aspx

它对我有用。

相关问题