Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

When User Login Success After Store UserName in session like below code
C#
protected void btnlogin_Click(object sender, EventArgs e)
   {Session["UserName"] = txtusername.Text;
}




Then Every page load check this session like below code


C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (Session["UserName"] != null)
       {
        }else
        {
            Response.Redirect("LoginPage.aspx");
        }

Any Doubts let me know..
 
Share this answer
 
v2
Comments
[no name] 28-Apr-12 6:18am    
i want that when user login successfully and then it become idle so it will be automatically logoff. and redirect to login page
sessionState timeout="1" mode="InProc"
write this in web.config after the time out session will expires accordingly.
 
Share this answer
 
Comments
[no name] 28-Apr-12 6:20am    
but according to your sugestion it look like user idle or not it redirect to login page after some time thats not wayy..

if idle then and only then log off.
[no name] 28-Apr-12 6:38am    
but thanks for your suggestion
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:

C#
if(Session["variableName"]==null)
{
Response.Redirect("YourLoginPage.aspx");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900