gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:08:55 24 4
gpt4 key购买 nike

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

我查看了一些教程,并提出了一个带有 BlobStorageContainerFactory 的简单存储库模式,以便我可以注入(inject)命名存储库。当我使用 Azure 存储本地开发模拟器时,此代码运行良好。这是工厂的代码:

    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

最佳答案

看起来 blob 存储连接字符串不允许在字符串末尾出现 ;

它们的顺序并不重要。

关于c# - Azure Blob 存储无效帐户字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25193368/

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