public ActionResult GetFile(string url, int id) { string redirectUrl; if (Request.UrlReferrer != null && Url.IsLocalUrl(Request.UrlReferrer.ToString())) { redirectUrl = Request.UrlReferrer.PathAndQuery; } else { redirectUrl = Url.Action("Index", "Home"); } StorageAccount account = _storageAccountService.Load(id); if (account == null) { TempData.AddRequestErrorMessage(ValidationResources.StorageAccountNotFoundError); return(Redirect(redirectUrl)); } if (string.IsNullOrEmpty(url)) { TempData.AddRequestErrorMessage(ValidationResources.InvalidFileLocation); return(Redirect(redirectUrl)); } if (User == null || User.Identity == null) { TempData.AddRequestErrorMessage(ValidationResources.NoPermissionsToDownload); return(Redirect(redirectUrl)); } if (account.UserId != User.Identity.UserId) { TempData.AddRequestErrorMessage(ValidationResources.NoPermissionsToDownload); return(Redirect(redirectUrl)); } try { var streamResult = _storagePluginsService.DownloadFile(account, url); return(new BufferLessFileResult(streamResult.FileStream, streamResult.FileName)); } catch (StoragePluginNotFoundException) { TempData.AddRequestErrorMessage(ValidationResources.StoragePluginNotFoundError); } catch (PluginException ex) { TempData.AddRequestErrorMessage(GetErrorMessage(ex.ErrorCode)); if (ex.ErrorCode == PluginErrorCodes.PluginError) { Logger.Error("Storage plugin error", ex); } } catch (Exception ex) { TempData.AddRequestErrorMessage(ErrorResources.PluginError); Logger.Error("Storage plugin error", ex); } return(Redirect(redirectUrl)); }