Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 引发状态为TrustFailure的WebException。AmazonS3.NET3.5Version3从sharepoint 2010调用_C#_Amazon S3_Sharepoint 2010_Aws Sdk - Fatal编程技术网

C# 引发状态为TrustFailure的WebException。AmazonS3.NET3.5Version3从sharepoint 2010调用

C# 引发状态为TrustFailure的WebException。AmazonS3.NET3.5Version3从sharepoint 2010调用,c#,amazon-s3,sharepoint-2010,aws-sdk,C#,Amazon S3,Sharepoint 2010,Aws Sdk,目前,我正在POC中使用AmazonS3 Sdk进行CRUD操作,该Sdk适用于.net 3.5版本3。我试图使用密钥和访问密钥以及bucket name(has Location:EU(Frankfurt)(EU-central-1))检索特定bucket名称的区域端点(位置)。为了建立联系 使用AmazonS3并执行CRUD操作 因此,当我试图从共享点(我使用SharePoint的母版页创建自己的网页)获取区域终结点,以便创建具有区域检索功能的AmazonS3Client实例时,引发了状态为

目前,我正在POC中使用AmazonS3 Sdk进行CRUD操作,该Sdk适用于.net 3.5版本3。我试图使用密钥和访问密钥以及bucket name(has Location:EU(Frankfurt)(EU-central-1))检索特定bucket名称的区域端点(位置)。为了建立联系 使用AmazonS3并执行CRUD操作 因此,当我试图从共享点(我使用SharePoint的母版页创建自己的网页)获取区域终结点,以便创建具有区域检索功能的AmazonS3Client实例时,引发了状态为TrustFailure的WebException。
使用以下代码:

private string defaultAmazonHttpsHost = "https://s3.amazonaws.com";
private string defaultAmazonHttpHost = "http://s3.amazonaws.com"; 

private Amazon.RegionEndpoint GetRegionEndpoint(string bucket, BasicAWSCredentials amazonCredentials, bool useSSL)
{
    Amazon.RegionEndpoint regiongEndpoint = null;
    AmazonS3Config configurationClient = new AmazonS3Config();
    configurationClient.UseHttp = !useSSL;
    configurationClient.ServiceURL = useSSL ? defaultAmazonHttpsHost : defaultAmazonHttpHost;
    try
    {
        using (AmazonS3Client clientConnection = new AmazonS3Client(amazonCredentials, configurationClient))
        {
            GetBucketLocationRequest locationRequest = new GetBucketLocationRequest();
            locationRequest.BucketName = bucket;
            string locationName = clientConnection.GetBucketLocation(locationRequest).Location.Value;
            if (locationName.Equals("EU", StringComparison.InvariantCultureIgnoreCase))
            {
                regiongEndpoint = Amazon.RegionEndpoint.EUWest1;
            }
            else if (string.IsNullOrEmpty(locationName))
            {
                regiongEndpoint = Amazon.RegionEndpoint.USEast1;
            }
            else
            {
                regiongEndpoint = Amazon.RegionEndpoint.GetBySystemName(locationName);
            }
        }
    }
    catch (AmazonS3Exception amazonS3Exception)
    {
          throw amazonS3Exception;
    }
    catch (Exception unExpectedException)
    {
        throw unExpectedException;
    }
    return regiongEndpoint;
}
BasicAWSCredentials credentials = new BasicAWSCredentials("my access Key", "my secret key");
AmazonS3Config configurationAmazon = new AmazonS3Config();
configurationAmazon.RegionEndpoint = GetRegionEndpoint("bucketName", credentials, false);
 AmazonS3Client _s3 = new AmazonS3Client(credentials, configurationAmazon );
我的任务使用AmazonS3 Sdk.net 3.5版本3执行CRUD操作+测试连接,源信息如下: -密钥 -访问密钥 -桶名


奇怪的是,如果这部分代码从另一个项目开始运行(执行)(没有共享点交互,例如:Console项目)我没有得到这个例外)你知道问题出在哪里吗?

我在执行对amazonS3的任何请求之前使用了以下命令,现在它可以正常工作了。我想问题出在sharepoint使用的证书上

ServicePointManager.ServerCertificateValidationCallback +=   
delegate(  
    object sender,   
    X509Certificate certificate,   
    X509Chain chain,   
    SslPolicyErrors sslPolicyErrors)  
    {  
         return true;  
    };  

提供一个关于它的解释

在执行对amazonS3的任何请求之前,我使用了以下命令,现在它可以正常工作了。我认为问题在于sharepoint使用的证书

ServicePointManager.ServerCertificateValidationCallback +=   
delegate(  
    object sender,   
    X509Certificate certificate,   
    X509Chain chain,   
    SslPolicyErrors sslPolicyErrors)  
    {  
         return true;  
    };  
这篇文章提供了一个解释,这里的关键点是“信任失败”。证书有点问题。在我的例子中,这个错误是由于我的公司使用Websense造成的,Websense是一个web过滤器/安全套件,它拦截并重新颁发https证书用于web流量,以便它可以监视您。即使您不使用类似的东西,底线是您的计算机不信任远程计算机正在使用的证书的颁发者。接收此错误的服务器在其受信任的根证书颁发机构中没有正确的证书。导入正确的受信任根证书()后,我不再收到错误

如果您认为情况并非如此,您可以通过将详细信息写入控制台或在控制台上放置断点来获取有关异常的更多详细信息。请在此处写入并实际检查证书和ssl错误:

using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

.....
.....
//before you make the request
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate (
    object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors)
{
    Console.WriteLine("Subject: " + certificate.Subject + ", Issuer: " + certificate.Issuer + ". SSL Errors: " + sslPolicyErrors.ToString());
    return false;
};
这里的关键点是,您需要找到证书问题并解决它,而不是忽略所有ssl错误而使自己易受攻击。

这里的关键点是“TrustFailure”。证书有点问题。在我的例子中,这个错误是由于我的公司使用Websense造成的,Websense是一个web过滤器/安全套件,它拦截并重新颁发https证书用于web流量,以便它可以监视您。即使您不使用类似的东西,底线是您的计算机不信任远程计算机正在使用的证书的颁发者。接收此错误的服务器在其受信任的根证书颁发机构中没有正确的证书。导入正确的受信任根证书()后,我不再收到错误

如果您认为情况并非如此,您可以通过将详细信息写入控制台或在控制台上放置断点来获取有关异常的更多详细信息。请在此处写入并实际检查证书和ssl错误:

using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

.....
.....
//before you make the request
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate (
    object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors)
{
    Console.WriteLine("Subject: " + certificate.Subject + ", Issuer: " + certificate.Issuer + ". SSL Errors: " + sslPolicyErrors.ToString());
    return false;
};

这里的关键点是,您需要找到证书问题并解决它,而不是忽略所有ssl错误而使自己容易受到攻击。

信任失败也可能是由于计算机上的日期不正确造成的

信任失败也可能是由于机器上的日期不正确造成的