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

.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页面来写