1、复制下列代码,拷贝到控制器中。
#region 生成验证码图片
// [OutputCache(Location = OutputCacheLocation.None, Duration = 0, NoStore = false)]
public ActionResult SecurityCode()
{
string oldcode = Session["SecurityCode"] as string;
string code = CreateRandomCode(5);
Session["SecurityCode"] = code;
return File(CreateValidateGraphic(code), "image/Jpeg");
}
private byte[] CreateImage(string checkCode)
{
int iwidth = (int)(checkCode.Length * 12);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
Graphics g = Graphics.FromImage(image);
Font f = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
Brush b = new System.Drawing.SolidBrush(Color.White);
g.Clear(Color.Blue);
g.DrawString(checkCode, f, b, 3, 3);
Pen blackPen = new Pen(Color.Black, 0);
Random rand = new
C# MVC 验证码
最新推荐文章于 2022-06-10 01:18:54 发布

最低0.47元/天 解锁文章
2626

被折叠的 条评论
为什么被折叠?



