验证码页面(代码全在后台):
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
// 验证码长度
private int codeLen = 4;
// 图片清晰度
private int fineness =90;
// 图片宽度
private int imgWidth = 55;
// 图片高度
private int imgHeight = 24;
// 字体家族名称
private string fontFamily = "Times New Roman";
// 字体大小
private int fontSize = 14;
// 字体样式
private int fontStyle = 0;
// 绘制起始坐标 X
private int posX = 0;
protected System.Web.UI.WebControls.Button Button1;
// 绘制起始坐标 Y
private int posY = 0;
private void Page_Load(object sender, EventArgs e)
{
//读取 Request 传递参数#region 读取 Request 传递参数
// 获取代码长度设置
if (Request["CodeLen"] != null)
{
try
{
codeLen = Int32.Parse(Request["CodeLen"]);
// 规定验证码长度
if (codeLen < 4 || codeLen > 16)
throw new Exception("验证码长度必须在4
到16之间");
}
catch (Exception ex)
{
throw ex;
}
}
// 获取图片清晰度设置
if (Request["Fineness"] != null)
{
try
{
fineness = Int32.Parse(Request["Fineness"]);
// 验证清晰度
if (fineness < 0 || fineness > 100)
throw new Exception("图片清晰度必须在0
到100之间");
}
catch (Exception Ex)
{
throw Ex;
}
}
// 获取图片宽度
if (Request["ImgWidth"] != null)
{
try
{
imgWidth = Int32.Parse(Request["ImgWidth"]);
if (imgWidth < 16 || imgWidth > 480)
throw new Exception("图片宽度必须在16到
480之间");
}
catch (Exception Ex)
{
throw Ex;
}
}
// 获取图片高度
if (Request["ImgHeight"] != null)
{
try
{
imgWidth = Int32.Parse(Request["ImgHei