【发布时间】:2018-11-21 04:38:30
【问题描述】:
我有一个 ASP.NET 应用程序,它可以成功地将图像上传到 azure 容器。我正在尝试创建一个删除 blob 中特定图像的函数,并从数据库中删除该图像。从数据库中删除它并不困难,但尝试从 azure 中删除它会引发异常。我在网上搜索了答案,但没有!什么都有帮助!下面是代码:
错误异常
An unhandled exception occurred while processing the request.
ArgumentNullException: Value cannot be null.
Parameter name: connectionString
Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(string connectionString)
InterfaceService.cs
public CloudBlobContainer GetBlobContainer(string azureCString, string containerName)
{
var account = CloudStorageAccount.Parse(AzureCString);
var blobClient = account.CreateCloudBlobClient();
return blobClient.GetContainerReference(containerName);
}
Products.cs
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}
var product = await _context.Product
.SingleOrDefaultAsync(m => m.Id == id);
if (product == null)
{
return NotFound();
}
return View(product);
}
[HttpPost, ActionName("Delete")]
public async Task<IActionResult> DeleteConfirmed(int id, IFormFile file)
{
var product = await _context.Product.SingleOrDefaultAsync(m => m.Id == id);
var container = _interfaceService.GetBlobContainer(AzureCString, "azureCstring");
var content = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
var fileName = content.FileName.Trim('"');
var blob = container.GetBlockBlobReference(fileName);
await blob.DeleteIfExistsAsync();
_context.Product.Remove(product);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
【问题讨论】:
-
异常?需要详细说明吗?
-
我添加了更多详细信息
-
如果您使用秘密管理器,这可能与秘密管理器有关
-
我希望是这样,但我没有使用秘密管理器。
-
您是否已逐步执行 GetBlobContainer 方法并验证您的字符串是否存在?我的猜测是它被提供为 null。
标签: c# asp.net azure-blob-storage