//myhandler?id=1 public void ProcessRequest(HttpContext context) { byte[] imageBytes = null; int id; if (int.TryParse(context.Request.QueryString["id"], out id)) { using (var db = new WallpaperContext()) { var wallpaper = db.Wallpapers.Find(id); if (wallpaper != null) { imageBytes = wallpaper.ImagesBytes; } } } if (imageBytes == null) { context.Response.StatusCode = 404; } else { context.Response.StatusCode = 200; context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(imageBytes); } }
protected override void Dispose(bool disposing) { if (disposing) { db?.Dispose(); db = null; } base.Dispose(disposing); }