Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I'm used forms authentication. I want to keep user log in forever until he log out explicit, how can I set this in configuration?
thanks.
Posted

Try using cookies. E.g.,
Response.Cookies["username"].Value=textBoxUsername.Text;
Response.Cookies["username"].Expires=DateTime.Now.AddDays(30);

This is one way. You can also use
HttpCookie cookie=new HttpCookie();
cookie.Value=textBoxUsername.Text;
cookie.Expires=DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);

Those are simple ways of using cookies. In my examples, the cookie expires 30 days from creation.
 
Share this answer
 
Comments
RaviRanjanKr 29-May-11 12:34pm    
Nice Solution, My 5 :)
Abhinav S 29-May-11 12:41pm    
Nice. 5.
You can use to storing login state in the session entirely, and store it in a cookie instead. That way, you could set the expiry to whatever you wanted, and they could stay logged in for a day, or a week, or forever, if you wanted.
for details have a go there[^] to read discussion.
 
Share this answer
 
hui,

it is the matter of expiring your session just google key word keep session alive will solve your problem


happy coding
 
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