C# 从IIS.Net ASP.Net使用AWS S3 API时,对象引用未设置为对象的实例

C# 从IIS.Net ASP.Net使用AWS S3 API时,对象引用未设置为对象的实例,c#,.net,amazon-web-services,amazon-s3,C#,.net,Amazon Web Services,Amazon S3,我正在尝试将文件保存到S3存储桶中。我将文件复制到临时位置只是为了证明(对我来说)文件存在并且可以访问。当然,这本书没有问题 最后一行不断抛出异常,详细信息显示“对象引用未设置为对象的实例” 我在S3调用中尝试了一些方法: 不同的键(尝试了“blah”一词) 不同的桶 发送 文件作为路径而不是流 因为我只提供了3个字段,所以我没有太多其他的地方可以尝试 我试图在代码之外保留身份验证,以便主机可以控制它 有什么想法吗 非常感谢 编辑: 这个问题都与IIS权限有关。AWS试图通过web.config

我正在尝试将文件保存到S3存储桶中。我将文件复制到临时位置只是为了证明(对我来说)文件存在并且可以访问。当然,这本书没有问题

最后一行不断抛出异常,详细信息显示“对象引用未设置为对象的实例”

我在S3调用中尝试了一些方法:

  • 不同的键(尝试了“blah”一词)
  • 不同的桶
  • 发送 文件作为路径而不是流
  • 因为我只提供了3个字段,所以我没有太多其他的地方可以尝试

    我试图在代码之外保留身份验证,以便主机可以控制它

    有什么想法吗

    非常感谢

    编辑:


    这个问题都与IIS权限有关。AWS试图通过web.config文件中的条目访问凭据:

    <configSections>
      <section name="aws" type="Amazon.AWSSection, AWSSDK.Core"/>
    </configSections>
    <aws profileName="default" profilesLocation="C:\Users\Administrator\.aws\credentials"/>
    
    
    


    AWS的错误非常严重。如果出现正确的错误消息,我将节省大量时间。

    请检查异常的堆栈跟踪,以确定引发异常的确切位置。只需c#观察…如果
    putRequest.InputStream=stream
    没有抛出异常,那么
    null
    必须是客户端…并且您尝试的任何操作都无法解决此问题;-)@GaretJax:使用任何反编译器(IlSpy都可以)反编译他们的API,并查看实现。检查他们是如何获取凭据的,以及您可以对此做些什么。它甚至可以是一些简单的东西(例如,您缺少正确的配置键/值)
    at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
    at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
    at Amazon.Runtime.Internal.CredentialsRetriever.PreInvoke(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.RetryHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext executionContext)
    at Amazon.Runtime.AmazonServiceClient.Invoke[TResponse](AmazonWebServiceRequest request, InvokeOptionsBase options)
    at MyCode.aspx.cs:line 260
    
    <configSections>
      <section name="aws" type="Amazon.AWSSection, AWSSDK.Core"/>
    </configSections>
    <aws profileName="default" profilesLocation="C:\Users\Administrator\.aws\credentials"/>