session为null
时间:2011-12-16
来源:互联网
代码如下:
C# code
JScript code
C# code
每当第一次打开页面的时候都会提示session为null
当页面刷新后能正常登陆
web.config里没有配置sessionState 只是在IIS的编辑配置里把会话状态模式设置成InProc 时间是30分钟
实在不懂是什么回事···向各位请教了··谢谢··
C# code
//把验证码放在session里 string so = "1,2,3,4,5,6,7,8,9,0,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[] strArr = so.Split(','); string code = ""; Random rand = new Random(); for (int i = 0; i < codeLength; i++) { code += strArr[rand.Next(0, strArr.Length)]; } Session.Add("Volidate", code); return code;
JScript code
//登陆代码: $.ajax({ type:"get", url:"/Register/checkUserLogin.ashx", data:{"loginUserName":$.trim($("#loginUserName").val()),"loginPassWord":$.trim($("#loginPassWord").val()),"loginSofeCode":$.trim($("#loginSofeCode").val())}, success:function(msg){ var errorMessage=""; var success="0"; switch(msg) { case "Serror": errorMessage="Security code is wrong!"; break; case "sessionnulll": errorMessage="sessionnull"; break; default: success="1"; break; } if(success=="0") { alert(errorMessage); } else { location.href='/'; } return false; }, error:function(msg){ alert(msg); location.reload(); } });
C# code
//checkUserLogin.ashx中的代码 string errorMessage = ""; string type = ""; try { string sofeCode = context.Request.QueryString["loginSofeCode"].ToString(); string loginPassWord = context.Request.QueryString["loginPassWord"].ToString().Trim(); string loginUserName = context.Request.QueryString["loginUserName"].ToString().Trim(); if (context.Session["Volidate"] == null) { errorMessage = "sessionnulll"; } else if (sofeCode.Trim() != context.Session["Volidate"].ToString().Trim()) { errorMessage = "Serror"; } else { } context.Response.ContentType = "text/plain"; context.Response.Write(errorMessage.ToString()); } catch (Exception ex) { context.Response.Write(ex.Message); }
每当第一次打开页面的时候都会提示session为null
当页面刷新后能正常登陆
web.config里没有配置sessionState 只是在IIS的编辑配置里把会话状态模式设置成InProc 时间是30分钟
实在不懂是什么回事···向各位请教了··谢谢··
作者: together14629 发布时间: 2011-12-16
断点。看看 第一次 为什么没给上值
难道是传说中的。。。。。。缓存?
难道是传说中的。。。。。。缓存?
作者: id270 发布时间: 2011-12-16
我到没碰到过这种情况。每次都是Session[""]=="";直接赋值的。楼主设置断点调试下看看。看第一次是否确定已经赋值成功
作者: liuleiyu121520 发布时间: 2011-12-16
C# code
第一次先清理session中的值
if (Session["Volidate"] != null) { Session["Volidate"] = null; Session.Add("Volidate", code); } else { Session.Add("Volidate", code); }
第一次先清理session中的值
作者: zgf_along 发布时间: 2011-12-16
各种的无语··我重新做了个测试页面···
C# code
各种的通过··
C# code
protected void btn_Click(object sender, EventArgs e) { Response.Write("<br/>--------------------------------------------------------------------------------------------------<br/>"); Response.Write("Session[\"Volidate\"] 是否存在<br/>"); if (Session["Volidate"] == null) { Response.Write("否"); } else { Response.Write("是<br/>"); Response.Write(String.Format("Session[\"Volidate\"] 在服务器上的值是: {0} 。<br/>", Session["Volidate"].ToString())); Response.Write(String.Format("提交的值是: {0} 。<br/>", txtcode.Text.Trim())); if (txtcode.Text.Trim().ToLower() == Session["Volidate"].ToString().ToLower()) { Response.Write("验证通过。<br/>"); } else { Response.Write("验证失败。<br/>"); } } }
各种的通过··
作者: together14629 发布时间: 2011-12-16
引用 4 楼 together14629 的回复:
各种的无语··我重新做了个测试页面···
C# code
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<br/>---------------------------------------------------------------------------……
各种的无语··我重新做了个测试页面···
C# code
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<br/>---------------------------------------------------------------------------……
那你解决了吗?
作者: MSDNXGH 发布时间: 2011-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28