public void ProcessRequest(HttpContext context) { context.Response.ClearHeaders(); context.Response.ClearContent(); context.Response.Clear(); context.Response.ContentType = "text/calendar"; try { string typeOfImage = context.Request.QueryString["type"]; string token = context.Request.QueryString["token"]; int id = Int32.Parse(context.Request.QueryString["ID"]); byte[] byteArrayImage = new byte[0]; string ipAddress = context.Request.ServerVariables["REMOTE_ADDR"].Replace(".", "").Replace(":", ""); if (String.IsNullOrEmpty(ipAddress)) { if (context.Request.UserHostAddress != null) { ipAddress = context.Request.UserHostAddress.Replace(".", "").Replace(":", ""); } } if (id > 0 && !string.IsNullOrEmpty(typeOfImage) && !string.IsNullOrEmpty(token)) { ValidSecurityToken(token, ipAddress); typeOfImage = typeOfImage.Trim().ToUpper(); switch (typeOfImage) { case "CLIENT": ClientsController client = new ClientsController(); byteArrayImage = client.GetClientPicture(id); break; case "PET": PetsController pet = new PetsController(); byteArrayImage = pet.GetPetPicture(id); break; case "USER": UsersController user = new UsersController(); byteArrayImage = user.GetUserPicture(id); break; case "COMPANY": CompaniesController company = new CompaniesController(); byteArrayImage = company.GetCompanyPicture(id); break; } if (byteArrayImage != null) { Bitmap bitmap = new Bitmap(ImageHelper.ByteToImage(byteArrayImage)); bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg); } else { Bitmap bitmap = new Bitmap(Image.FromFile(context.Server.MapPath("~/Images/photo.png"))); bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg); } } else { Bitmap bitmap = new Bitmap(ImageHelper.DrawTextImage("Invalid QueryString", Color.Red, Color.WhiteSmoke)); bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg); } } catch (Exception ex) { Bitmap bitmap = new Bitmap(ImageHelper.DrawTextImage(ex.Treatment(true), Color.Red, Color.WhiteSmoke)); bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg); } }