郁闷死了,登陆问题. cookie
辛辛苦苦做了一个web项目,传到服务器上出登陆问题了.大伙帮忙看看有什么问题.谢谢
登陆页(Login.aspx):
if (用户名密码正确)
{
HttpCookie user = new HttpCookie( "用户 ", userbox.Text);
HttpCookie name = new HttpCookie( "姓名 ", table1.Rows[0][0].ToString());
HttpCookie other = new HttpCookie( "权限 ", table.Rows[0][1].ToString());
user.Expires = DateTime.Now.AddMinutes(30);
name.Expires = DateTime.Now.AddMinutes(30);
other.Expires = DateTime.Now.AddMinutes(30);
Response.AppendCookie(user);
Response.AppendCookie(name);
Response.AppendCookie(other);
Response.Redirect( "index.htm? " + userbox.Text, true);
}
index.htm是一个框架静态页面,用于链接其他数据库操作页面.
数据库操作页的Load事件:
if (Request.Cookies[ "用户 "].Value == null)
{
Response.Redirect( "../../Login.aspx ", true);
}
else
{
if (Request.Cookies[ "权限 "].Value == "管理员 ")
{
AccessDataSource1.SelectCommand = string.Format( "select * from xxx表 "); //设置GridView1的数据源
GridView1.AutoGenerateEditButton = true;
GridView1.AutoGenerateDeleteButton = true;
}
}
问题:
通过登陆页面可以正常登陆到index.htm,在index.htm中点击其它数据库操作页的链接,链接可以在框架中正常显示,一直不停的操作也没问题.但是当页面空闲一两分钟以后再点击链接,框架就重定向到Login.aspx了(Request.Cookies[ "用户 "].Value == null),但这个时候不理框架,继续点击链接,框架里页面又可以正常显示了.Cookies的值获取也正常了,但却不能往库里插数据了,重登陆就一切正常.(如果页面空闲还会象上面一样),我调了三天,没头绪啊!!大家帮帮忙看看把.目标是做到空闲不用重登陆.
我 web.Config 的配置:
<sessionState timeout= "6000 " mode= "InProc " stateNetworkTimeout= "6000 " cookieless= "false "> </sessionState>
<anonymousIdentification cookieless= "UseDeviceProfile " cookieTimeout= "6000 "/>
------解决方案--------------------Cookies 有时限啊
------解决方案--------------------你别用cookie,用session吧
可以设置有效时间,在多久的时间里不操作session就消失
------解决方案--------------------protected HttpCookie ckie = new HttpCookie( "RelayMange ");
ckie.Values.Add( "userid ", Server.UrlEncode(userSet.Tables[0].Rows[0][ "id "].ToString()));
ckie.Values.Add( "name ", Server.UrlEncode(userSet.Tables[0].Rows[0][ "name "].ToString()));
ckie.Values.Add( "username ", Server.UrlEncode(userSet.Tables[0].Rows[0][ "Name_Login "].ToString()));
ckie.Values.Add( "roleid ", Server.UrlEncode(userSet.Tables[0].Rows[0][ "role_id "].ToString()));
ckie.Values.Add( "rolename ", Server.UrlEncode(userSet.Tables[0].Rows[0][ "rolename "].ToString()));
Response.AppendCookie(ckie);
Response.Redirect( "index.aspx ");
用的时候:
HttpCookie GetCookie = Request.Cookies[ "RelayMange "];