日期:2014-05-18  浏览次数:20488 次

请教一个验证码值的问题
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

public partial class gif : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  string tmp = RndNum(4); 
  HttpCookie a = new HttpCookie("pic",tmp); 
  Response.Cookies.Add(a); 
  this.ValidateCode(tmp);
   
  }
  private void ValidateCode(string VNum) 
  { 
  Bitmap Img=null; 
  Graphics g=null; 
  MemoryStream ms=null; 

  int gheight=VNum.Length*12; 
  Img=new Bitmap(gheight,25); 
  g=Graphics.FromImage(Img); 
  //背景颜色 
  g.Clear(Color.Blue);  
  //文字字体 
  Font f=new Font("Arial Black",10); 
  //文字颜色 
  SolidBrush s=new SolidBrush(Color.Red); 
  g.DrawString(VNum,f,s,3,3); 
  ms=new MemoryStream(); 
  Img.Save(ms,ImageFormat.Jpeg); 
  Response.ClearContent(); 
  Response.ContentType="image/Jpeg"; 
  Response.BinaryWrite(ms.ToArray()); 

  g.Dispose(); 
  Img.Dispose(); 
  Response.End(); 
  } 
  private string RndNum(int VcodeNum) 
  { 
  string Vchar="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; 
  string[] VcArray=Vchar.Split(new Char [] {','}); 
  string VNum=""; 
  int temp=-1; 

  Random rand=new Random(); 

  for(int i=1;i<VcodeNum+1;i++) 
  { 
  if(temp!=-1) 
  { 
  rand=new Random(i*temp*unchecked((int)DateTime.Now.Ticks)); 
  } 

  int t=rand.Next(35); 
  if(temp!=-1&&temp==t) 
  { 
  return RndNum(VcodeNum); 
  } 
  temp=t; 
  VNum+=VcArray[t]; 
  } 
  return VNum; 
  } 

}
这段gif.aspx.cs代码产生的验证码图片怎么读出来呢?
用Response.Cookies["pic"].Value怎么取不到验证值呢?
要怎么才能取到产生的验证码值呢?

------解决方案--------------------
用Response.Cookies["pic"].Value怎么取不到验证值呢? 

是Request.Cookies["pic"].Value
------解决方案--------------------
http://blog.csdn.net/ChengKing/archive/2007/01/05/1475140.aspx