驗證碼 我在.net程序裡用了一個asp(code.asp) 的驗證碼因code.asp傳過來的 Session值是Session("checkcode")--是園擴號這個Session在.net程序裡可以用嗎??不能用的話是不是還要寫個.net的驗證碼?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 asp的驗證碼比較漂亮..所以最好就用這個版本的 我有验证码。。HOHOH.................独家开创的。。 ASP.net的session和asp的session要共用好象要配置下具体你查查网上资料哈 aspx下的验证码类比较多用的也很方便,asp存在seeion中的值是否可用楼主可以试一下,如果不行的话,可以放在cookie中,这样应该可以用aspx读取 我剛好也在做這個,代碼給你可以直接用的 protected void Page_Load(object sender, EventArgs e) { string checkCode = CreateRandomCode(6); Session["CheckCode"] = checkCode; CreateImage(checkCode); } private string CreateRandomCode(int codeCount) { string allChar = "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,W,X,Y,Z"; string[] allCharArray = allChar.Split(','); string randomCode = ""; int temp = -1; Random rand = new Random(); for (int i = 0; i < codeCount; i++) { if (temp != -1) { rand = new Random(i * temp * ((int)DateTime.Now.Ticks)); } int t = rand.Next(35); if (temp == t) { return CreateRandomCode(codeCount); } temp = t; randomCode += allCharArray[t]; } return randomCode; } private void CreateImage(string checkCode) { int iwidth = (int)(checkCode.Length * 11.5); System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image); System.Drawing.Font f = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold); System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.White); //g.FillRectangle(new System.Drawing.SolidBrush(Color.ed),0,0,image.Width, image.Height); g.Clear(System.Drawing.Color.Red); g.DrawString(checkCode, f, b, 3, 3); //System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black, 0); Random rand = new Random(); for (int i = 0; i < 5; i++) { int y = rand.Next(image.Height); //g.DrawLine(blackPen, 0, y, image.Width, y); } System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); Response.ClearContent(); Response.ContentType = "image/Jpeg"; Response.BinaryWrite(ms.ToArray()); g.Dispose(); image.Dispose(); }<asp:Image Runat="server" ID="ImageCheck" ImageUrl="confirm.aspx"></asp:Image> 你那段代码 是执行在ASP页面 当然可以执行的 但是SESSION共享 好不好用 就不确定了你取值 试试 一定要考虑编码问题 一个插入问题,判断是否为空、是否为数字。 关于验证保存在session中怎么更新的问题? listbox鼠标经过行变色,光标变手型以及双击事件怎么做? 添加Word组件没反应 泰哥,请进! 如何实现无刷新上传文件 App_Code文件 用模拟对话框修改数据的问题 从客户端(zuopinzhanshi_zpjs="<IMG height=182 alt=...")中检测到有潜在危险的 Request.Form 值。 vs2012 双击打开单文件时 提示 值不在预期的范围内 有人写过asp.net的性能分析吗? session传的值为什么会变
独家开创的。。
{
string checkCode = CreateRandomCode(6);
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
}
private string CreateRandomCode(int codeCount)
{
string allChar = "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,W,X,Y,Z";
string[] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1; Random rand = new Random();
for (int i = 0; i < codeCount; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(35);
if (temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}
private void CreateImage(string checkCode)
{
int iwidth = (int)(checkCode.Length * 11.5);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
System.Drawing.Font f = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.White);
//g.FillRectangle(new System.Drawing.SolidBrush(Color.ed),0,0,image.Width, image.Height);
g.Clear(System.Drawing.Color.Red);
g.DrawString(checkCode, f, b, 3, 3); //System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black, 0);
Random rand = new Random();
for (int i = 0; i < 5; i++)
{
int y = rand.Next(image.Height);
//g.DrawLine(blackPen, 0, y, image.Width, y);
} System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
g.Dispose();
image.Dispose();
}<asp:Image Runat="server" ID="ImageCheck" ImageUrl="confirm.aspx"></asp:Image>