如何保持Web窗体的会话 [英] How to keep session for Web Form

查看:57
本文介绍了如何保持Web窗体的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不会发生错误,必须维持10分钟的会话,然后应将页面重定向到登录表单...我该怎么做??? /div>

您需要在web.config文件中设置 SeessionTimeOut 值.


您可以通过以下代码通过用户名和密码登录时保持会话

会话[" ] = userId; 



好的,
现在,您应该从登录页面转到默认页面,例如.
在默认页面加载中,您必须检查用户登录是否有效,然后向用户显示此页面,否则用户将被重定向到登录页面.此行代码必须添加到默认页面加载或您要转到的另一页面:

 如果(会话["  userId"] == " );


Error won''t occoured,for 10 minute session have to maintain, then it should redirect the page to login form...how can i do this????

解决方案

you need to set SeessionTimeOut value in web.config file.


you can keep session when user login by username and Password by below code

session["userId"]=userId;//i assume that you have a table in database with userId,userName and password Fields and get userIdby connect to database by userName and Password



ok,
now you should go to from login page to default page,for example.
in default page load you must check if user login is valid then show this page to user and otherwise user mus be redirect to login page .this line of code must added to default page load or another page that your going to go there:

if (session["userId"]==null)
  response.redirect("Login.aspx");


这篇关于如何保持Web窗体的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆