public IActionResult GetCaptchaImage() { int width = 120; int height = 36; var captchaCode = CaptchaHelper.GenerateCaptchaCode(); var result = CaptchaHelper.GenerateCaptchaImage(width, height, captchaCode); HttpContext.Session.SetString("CaptchaCode", result.CaptchaCode); Stream s = new MemoryStream(result.CaptchaByteData); return(new FileStreamResult(s, "image/png")); }