Controller中调用的方式: public ActionResult CheckCode() { ValidateCode2 vCode = new ValidateCode2(); string code = vCode.CreateRandomCode(4); Session["ValidateCode"] = code; byte[] bytes = vCode.CreateImage(code); return File(