У меня есть приложение 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);
}
Продукты.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));
}