HttpHandler对象实现验证码
1.添加一个HttpHandler类,继承IHttpHandler与IRequiresSessionState接口
public class VerificationCode : IHttpHandler,IRequiresSessionState
{
//定义一个随机对象
private Random random = new Random();
public void ProcessRequest(HttpContext context)
{
int a = random.Next(0, 9);
int b = random.Next(0, 9);
int c = random.Next(0, 9);
int d = random.Next(0, 9);
string code = "";
code = code + a + b + c + d;
//将验证码放入 Session 作用域
context.Session[