public FileContentResult ImageValidator() { Response.Cache.SetCacheability(HttpCacheability.NoCache); VerifyImage v = new VerifyImage(); string code = v.CreateVerifyCode(); CookieHelper.SaveCookie <String>("VerifyCode", code); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { Bitmap image = v.CreateImageCode(code); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); code = CryptoManager.Encrypt(code.ToUpper()); byte[] b = ms.GetBuffer(); return(File(b, @"image/jpg")); } }