首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

.net 中 判断验证码输入是否正确解决办法

2012-03-22 
.net 中 判断验证码输入是否正确//Request.Cookies[textbox7].Value//这个是获取存在Cookie中的验证码

.net 中 判断验证码输入是否正确
//Request.Cookies["textbox7"].Value;//这个是获取存在Cookie中的验证码
假如页面要你输入验证码的文本框为的ID为CheckCode,那么判断如下:
if(textbox7.Text==Request.Cookies["textbox7"].Value)
{
//验证通过所要执行的代码
}
else
{
//验证失败
}
我用以上代码来判断,但是总会出现“未将对象引用设置到对象的实例”指示的是这行代码if(textbox7.Text==Request.Cookies["textbox7"].Value);

我是哪里出错了呢?

[解决办法]
Request.Cookies["textbox7"].Value没取到值吧?你调试看看
[解决办法]

探讨
//Request.Cookies["textbox7"].Value;//这个是获取存在Cookie中的验证码
假如页面要你输入验证码的文本框为的ID为CheckCode,那么判断如下:
if(textbox7.Text==Request.Cookies["textbox7"].Value)
{
//验证通过所要执行的代码
}
else
{
//验证失败
}
我用以上代码来判……

[解决办法]
探讨

引用:
//Request.Cookies["textbox7"].Value;//这个是获取存在Cookie中的验证码
假如页面要你输入验证码的文本框为的ID为CheckCode,那么判断如下:
if(textbox7.Text==Request.Cookies["textbox7"].Value)
{
//验证通过所要执行的代码
}
els……

[解决办法]
你可以if(Request.Cookies["textbox7"]!=null)
{
if(textbox7.Text==Request.Cookies["textbox7"].Value)
{
//验证通过所要执行的代码
}
else
{
//验证失败
}

}
[解决办法]
探讨

引用:
引用:
//Request.Cookies["textbox7"].Value;//这个是获取存在Cookie中的验证码
假如页面要你输入验证码的文本框为的ID为CheckCode,那么判断如下:
if(textbox7.Text==Request.Cookies["textbox7"].Value)
……

[解决办法]
加httpcontext或者context试试....
[解决办法]
没有的时候你就给啊,在执行这代码之前就向客服端输出cookie
Response.Cookies.Add(new HttpCookie("textbox7", "这里就是你想要的验证码"));
[解决办法]
C# code
 HttpCookieCollection hccCookie = new HttpCookieCollection(); //得到用戶端Cookie hccCookie = Request.Cookies; //得到所有Key string[] sArr = hccCookie.AllKeys; Response.Write("hccCookie.allKeys 數量"+sArr.Length+"<br>");
[解决办法]
HttpContext.Current.Request.Cookies[""]试试
[解决办法]
Response.Cookies.Add(new HttpCookie("textbox7", "这里就是你想要的验证码"));
这句话写在GenerateCheckCode这个里面
另外提醒下,验证码真正的值我们一般保存在session中的,不放到客服端去,而且生成验证码的页面一般用ashx页面来写

热点排行