当前位置:编程学习 > C#/ASP.NET >>

asp.net随机验证码(使用ashx)

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();

补充:asp.net教程,.Net开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,