gpt4 book ai didi

Azure存储错误: Object reference not set to an instance of an object

转载 作者:行者123 更新时间:2023-12-03 06:00:25 25 4
gpt4 key购买 nike

我最近升级了几个项目。现在,由于某种原因,当我尝试创建新容器时,我使用相同的代码并收到有关对象引用的错误。我卸载了所有软件包并重新安装了它们。我确保引用了 System.Configuration。我不知道还能做什么。

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Auth;

try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(AnyFolder);
container.CreateIfNotExists();
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
catch (Exception ex)
{
Response.Write(ex);
}

最佳答案

您很可能将连接字符串放入应用设置中,而不是 web.config 文件中的连接字符串。

我建议尝试使用以下代码行来加载连接字符串,或者将连接字符串移动到 web.config 的连接字符串部分

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionStr‌​ing"]);

关于Azure存储错误: Object reference not set to an instance of an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32257359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com