空闲一段时间后自动注销
问题描述:
我想为我的网站提供便利,让用户空闲几分钟,它将自动进行会话破坏.
所以我该怎么办,解决方案是什么.
请给答案...
提前谢谢...
Mitesh
i want to give facility for my website in which user will idle for some minutes it will automatically session destroy.
so what can i do and what is the solution for it.
please give answer...
Thanks in advance...
Mitesh
答
将用户名存储在会话中后,成功登录用户后,如下面的代码
When User Login Success After Store UserName in session like below code
protected void btnlogin_Click(object sender, EventArgs e)
{Session["UserName"] = txtusername.Text;
}
然后每个页面加载检查此会话,如下面的代码
Then Every page load check this session like below code
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
}else
{
Response.Redirect("LoginPage.aspx");
}
任何疑问都让我知道.
Any Doubts let me know..
sessionState timeout ="1" mode ="InProc"
在超时会话将相应到期后,将其写入web.config.
sessionState timeout="1" mode="InProc"
write this in web.config after the time out session will expires accordingly.
只需在web.config
中设置超时 成功登录后,在应用程序中获取一个会话变量,并为其分配一些值.
和jus在页面Load上检查:此会话变量是否具有某些值或为null,如果为null,请转到登录页面
在页面加载时,输入:
Hi,
Just set the timeout in web.config
Take a session variable in your application and assign some value to it after successful login.
and jus check on page Load: whether this session variable have some value or it is null, in case of null just go to the login page
On page load, put:
if(Session["variableName"]==null)
{
Response.Redirect("YourLoginPage.aspx");
}