【www.gdgbn.com--安卓教程】

ValidateCode.ashx

<%@ WebHandler Language="C#" Class="ValidateCode" %>
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Drawing;

    public class ValidateCode : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//特别注意,如不加,单击验证图片'看不清换一张',无效果.
            this.CreateCheckCodeImage(GenerateCheckCode(context),context);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string GenerateCheckCode(HttpContext context)
        {
            int number;
            char code;
            string checkCode = String.Empty;

            System.Random random = new Random();

            for (int i = 0; i < 6; i++)
            {
                number = random.Next();

本文来源:http://www.gdgbn.com/shoujikaifa/14651/