想请问下这个问题是怎么回事,怎么解决呢?
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
namespace EF06URL重写
{
public class VerificationCode : IHttpHandler
{
public bool IsReusable => throw new NotImplementedException();
Random RandomSeed = new Random();
public void ProcessRequest(HttpContext context)
{
string strWord = "123456789QWERTYUIOPASDFGHJKLZXCVBNM";
string NumStr = null;
for (int i = 0; i < 5; i++)
{
NumStr += strWord[RandomSeed.Next(0, strWord.Length)];
}
context.Session["vcode"] = NumStr.ToLower();
CreateImages(context, NumStr);
}
private void CreateImages(HttpContext context, string numStr)
{
int iwidth = numStr.Length * 13;
Bitmap image = new Bitmap(iwidth, 22);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.White);
Color[] colors = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan };
string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };
Random rand = new Random();
for (int i = 0; i < 50; i++)
{
int x = rand.Next(image.Width);
int y = rand.Next(image.Height);
g.DrawRectangle(new Pen(Color.LightGray, 0), x, y,1,1);
}
for (int i = 0; i < numStr.Length; i++)
{
int cIndex = rand.Next(7);
int fIndex = rand.Next(5);
Font f = new System.Drawing.Font(font[fIndex], 10, FontStyle.Bold);
Brush b = new System.Drawing.SolidBrush(colors[cIndex]);
int ii = 4;
if ((i + 1) % 2 == 0)
{
ii = 2;
}
g.DrawString(numStr.Substring(i, 1), f, b, 2 + (i * 12), ii);
}
g.DrawRectangle(new Pen(ColorTranslator.FromHtml("#CCCCCC"), 0), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();//保存到内存当中
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//把图片以jpeg保存到ms流当中
context.Response.ClearContent();
context.Response.ContentType = "image/gif";
context.Response.BinaryWrite(ms.ToArray());
g.Dispose();
image.Dispose();
}
}
}