2

我的 Silverlight 客户端和 REST Web 服务器(使用 ASP.NET 处理程序实现)都在同一个域中。HTTP 和 HTTPS 协议绑定都在 IIS 7.0 中配置

当使用 HTTPS 请求 URI 时,我得到错误”消息:“安全错误。”但是相同的 URI 在 HTTP 请求上工​​作得很好,没有任何错误

private void btnLoginWebRequest_Click(object sender, RoutedEventArgs e)
    {


       bool httpResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
       bool httpsResult = WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);

      this.Dispatcher.BeginInvoke(()=>
      {
        WebClient webClient = new WebClient();
        webClient.Headers["CustomHeader"] = String.Format("myHeaders={0}", "Value");
        webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
        webClient.OpenReadAsync(new Uri(@"https://xxx.xx.xxx.xxx/MyRESTApi/UserGroups"));
       });
    }
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (e.Error == null)
    {
    }
}

I Get a Error and e.Error 包含以下错误信息

{System.Security.SecurityException: Security error.
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
   at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
    [System.Security.SecurityException]: {System.Security.SecurityException: Security error.
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
   at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
    Data: {System.Collections.ListDictionaryInternal}
    InnerException: null
    Message: "Security error."
    StackTrace: "   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)\r\n   at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)"

crossdomain.xml 如下:-

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*" secure="true"/>
    <allow-http-request-headers-from domain="*" headers="*" secure="true"/>
</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="https://"/>
            <domain uri="http://"/>
          </allow-from>      
          <grant-to>      
            <resource path="/" include-subpaths="true"/>
          </grant-to>      
        </policy>
      </cross-domain-access>

</access-policy>

我已经看到许多与堆栈溢出类似错误相关的线程,但无法通过这些线程中提供的任何解决方案解决此问题。我错过了什么吗?

4

0 回答 0