//[OutputCache(Duration = 60 * 60 * 24 * 30, Location = OutputCacheLocation.Downstream)] public ActionResult Image(int assetId, string fileName, string extension, int?cropSizeId) { var qs = Request.Url.Query; var settings = ImageResizeSettings.ParseFromQueryString(qs); var asset = _queryExecutor.GetById <ImageAssetRenderDetails>(assetId); if (asset == null) { return(FileAssetNotFound("Image could not be found")); } if (SlugFormatter.ToSlug(asset.FileName) != fileName) { var url = _imageAssetRouteLibrary.ImageAsset(asset, settings); return(RedirectPermanent(url)); } DateTime lastModified = DateTime.SpecifyKind(asset.UpdateDate, DateTimeKind.Utc); // Round the ticks down (see http://stackoverflow.com/a/1005222/486434), because http headers are only accurate to seconds, so get rounded down lastModified = lastModified.AddTicks(-(lastModified.Ticks % TimeSpan.TicksPerSecond)); if (!string.IsNullOrEmpty(Request.Headers["If-Modified-Since"])) { DateTime ifModifiedSince; if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out ifModifiedSince) && lastModified <= ifModifiedSince.ToUniversalTime()) { return(new HttpStatusCodeResult(304, "Not Modified")); } } Stream stream = null; try { stream = _resizedImageAssetFileService.Get(asset, settings); } catch (FileNotFoundException ex) { // If the file exists but the file has gone missing, log and return a 404 _errorLoggingService.Log(ex); return(FileAssetNotFound("File not found")); } // Expire the image, so browsers always check with the server, but also send a last modified date so we can check for If-Modified-Since on the next request and return a 304 Not Modified. Response.Cache.SetExpires(DateTime.UtcNow.AddMonths(-1)); Response.Cache.SetLastModified(lastModified); var contentType = MimeMapping.GetMimeMapping(asset.Extension); return(new FileStreamResult(stream, contentType)); }
private void LoopThroughInnerExceptions(Exception ex, Action <string> action) { while (ex != null) { _errorLogger.Log(ex); action(ex.Message); ex = ex.InnerException; } }
private void Execute(Action action) { try { action?.Invoke(); } catch (Exception ex) { _errorLoggingService.Log(ex.Message); } }
private void HandleDeserializationError(object sender, ErrorEventArgs errorArgs) { if (Debugger.IsAttached) { Debug.Assert(false, errorArgs.ErrorContext.Error.Message); } else { _errorLoggingService.Log(new Exception(errorArgs.ErrorContext.Error.Message)); } errorArgs.ErrorContext.Handled = true; }
private void FileSystemWatcher_Error(object sender, ErrorEventArgs e) { _errorLoggingService.Log(e.GetException().Message); }
protected override void OnException(ExceptionContext filterContext) { _logger.Log(filterContext.Exception); filterContext.Result = RedirectToAction("Index", "Error"); }
private void LogTooManyFailures() { _logger.Log(new ApplicationException($"Exceeded allowable number of consecutive failures ({MaxConsecutiveErrorsAllowed})")); }