当前位置: 首页 > 知识库问答 >
问题:

Azure Blob存储无效帐户字符串错误

江鸿羲
2023-03-14

我在连接到ASP. NET MVC5中的Azure Blob存储帐户时遇到问题。

我看了一些教程,提出了一个带有BlobStorageContainerFactory的简单存储库模式,这样我就可以注入命名的存储库。当我使用Azure Storage local development emulator时,这段代码运行良好。以下是工厂代码:

    public class BlobStorageContainerFactory
    {
        private CloudStorageAccount _storageAccount;
        private CloudBlobClient _blobClient;
        public CloudBlobContainer Get(string containerName)
        {
            //i want to get the connection string from the web.config eventually
            //_storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["BattleBornPrepsStorageConnection"].ConnectionString);

            //error occurs here
            _storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=myaccountnamealllower;AccountKey=theprimaryaccountkeyfromazuremanagementportal;");

            _blobClient = _storageAccount.CreateCloudBlobClient();
            var container = _blobClient.GetContainerReference(containerName);

            if (container.CreateIfNotExist())
            {
                // configure container for public access
                var permissions = container.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                container.SetPermissions(permissions);
            }

            return container;
        }
    }

我尝试解析连接字符串时出错:

An exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.StorageClient.dll but was not handled in user code

Additional information: Invalid account string.

堆栈跟踪:

[FormatException: Invalid account string.]
   Microsoft.WindowsAzure.CloudStorageAccount.<Parse>b__0(String err) +34
   Microsoft.WindowsAzure.CloudStorageAccount.ParseStringIntoSettings(String s, Action`1 error) +344
   Microsoft.WindowsAzure.CloudStorageAccount.TryParse(String s, CloudStorageAccount& accountInformation, Action`1 error) +19
   Microsoft.WindowsAzure.CloudStorageAccount.Parse(String value) +135
   MyProject.Data.BlobStorageContainerFactory.Get(String containerName) in f:\!ClientFiles\MyFiles\MyProject\LocalRepository\trunk\Release\MyProject\MyProject.Data\BlobStorageContainerFactory.cs:19
   MyProject.Data.StorageRepository..ctor(String containerName) in f:\!ClientFiles\MyFiles\MyProject\LocalRepository\trunk\Release\MyProject\MyProject.Data\StorageRepository.cs:20
   MyProject.Data.PublicationStorageRepository..ctor() in f:\!ClientFiles\MyFiles\MyProject\LocalRepository\trunk\Release\MyProject\MyProject.Data\PublicationStorageRepository.cs:12
   DynamicInjectorc89300dbc50f4bd49b75f3ea31ffe3e6(Object[] ) +71
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +884
   Ninject.Activation.Context.ResolveInternal(Object scope) +218
   Ninject.Activation.Context.Resolve() +216
   Ninject.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) +86
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4098209
   Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) +169
   Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) +747
   Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) +269
   Ninject.Activation.Providers.<>c__DisplayClass4.<Create>b__2(ITarget target) +69
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +335
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +847
   Ninject.Activation.Context.ResolveInternal(Object scope) +218
   Ninject.Activation.Context.Resolve() +277
   Ninject.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) +86
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4098209
   Ninject.Web.Mvc.NinjectDependencyResolver.GetService(Type serviceType) +145
   Castle.Proxies.Invocations.IDependencyResolver_GetService.InvokeMethodOnTarget() +138
   Castle.DynamicProxy.AbstractInvocation.Proceed() +117
   Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +48
   Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +195
   Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult) +198
   Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +45
   Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +183
   Castle.DynamicProxy.AbstractInvocation.Proceed() +483
   Castle.Proxies.IDependencyResolverProxy.GetService(Type serviceType) +187
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +87

[InvalidOperationException: An error occurred when trying to create a controller of type 'MyProject.Ui.Mvc.Areas.Admin.Controllers.PublicationController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +257
   Castle.Proxies.Invocations.IControllerFactory_CreateController.InvokeMethodOnTarget() +197
   Castle.DynamicProxy.AbstractInvocation.Proceed() +117
   Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +48
   Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +195
   Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult) +198
   Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +45
   Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +183
   Castle.DynamicProxy.AbstractInvocation.Proceed() +483
   Castle.Proxies.IControllerFactoryProxy.CreateController(RequestContext requestContext, String controllerName) +202
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +326
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +157
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

共有2个答案

方航
2023-03-14
<connectionStrings>      
    <add name="AzureStorageAccount" connectionString="DefaultEndpointsProtocol=https;AccountName=testdata;Accoun‌​tKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;"/>
</connectionStrings>

但有时它不起作用,会克服错误

“System”类型的未处理异常。Microsoft中发生“FormatException”。WindowsAzure。存储dll

附加信息:没有找到帐户信息的有效组合。然后请尝试使用以下代码:测试和工作100%

var accountName = "test2rdsfdg462";
var keyValue = "1gy3lpE7Du1j5ljKiupgKzywSfsdfdsfsdfsdfsdfsdfsdqGxd7/YThisv/OVVLfIOv9kQ==";
var useHttps = true;
var connValid = true;

var storageCredentials = new StorageCredentials(accountName, keyValue);
var storageAccount = new CloudStorageAccount(storageCredentials, useHttps);
var conString = storageAccount.ToString(connValid);

CloudStorageAccount sa = CloudStorageAccount.Parse(connString);
羊舌赞
2023-03-14

看起来blob存储连接字符串不允许 位于字符串末尾。

它们的顺序并不重要。

 类似资料:
  • 我使用ServiceBustigger创建了一个Azure Function应用程序(监听主题订阅)。很好。但是现在我试图制作一个QueueTrigger来监听一个简单的队列,但是我得到了以下错误。 我也是这样做的。我在Visual Studio中创建了一个新项目,并将其指向我在Azure上的存储帐户。指定了队列名称。队列存在。我尝试创建一个新的共享访问策略。已将连接字符串复制到本地。设置。jso

  • 我有一个函数应用,定义如下 其中< code > let-test-this-in 和< code > let-test-this-out 是连接字符串为< code >“defaultendpointsprocol=”的存储帐户下现有存储队列的名称...;account name =…;AccountKey= ... "(直接从门户中的访问键-连接字符串复制而来)。我发布时生成的function

  • 首先,我将引用另外两个对这个问题有部分答案的问题。 删除VM后从Azure中删除磁盘 如何删除Microsoft Azure存储中的租用blob 使用Azure Explorer,我可以删除blob和容器,但当我尝试删除存储帐户时,我出现了以下错误: 删除存储帐户“bitnamiWestusflwdmy”失败。无法删除存储帐户“bitnamiWestusflwdmy”:“存储帐户bitnamiWe

  • 我有一个Azure函数,应该处理存储帐户容器中的文件。应每天触发Azure函数。但是每周一两次,我看到容器中的一些文件没有被处理:(开始时,600中的401个文件没有被处理,因为错误403) 正如我在Stackoverflow中读到的。这是因为SAS令牌时间偏差。有没有可能在我的代码中没有大的变化,我解决了这个问题? 我的代码: 最新消息 执行函数时出现消息异常:通过\u http\u触发器\u活

  • 我在 Azure 表存储中有下表名称。表名是在我的应用程序中自动生成的,然后使用表创建。创建如果不存在(表名)。有些有效,有些则不然。当我深入研究错误时,扩展的错误信息告诉我资源名称包含无效字符 - 但是我无法弄清楚失败名称中无效的内容 - 任何人都可以发现这一点吗? -指定的资源名称包含无效字符 -指定的资源名称包含无效字符 –工程

  • 我将遵循下面的microsoft教程,并尝试使用mvn azure functions:deploy命令部署我的azure功能。我的函数app name/artifactid是ci cd demo:https://azure.microsoft.com/en-us/resources/videos/azure-friday-java-in-azure-functions/ 但是,我收到一个错误: