C# .NET - Authomatic log off - Asked By Dom Afonso on 13-Sep-12 05:18 AM

I am developing asp.net project that includes log in and off functionality. Now I want a c# code that can logg off the account if passed 3 minutes without having anyone move the mouse or press any key on the keyboard.
hiren dhameliya replied to Dom Afonso on 13-Sep-12 06:19 AM

If you are using forms authentication then you can use FormsAuthentication.SignOut();

this will work as long as you have set up ur website for form authentication in the config like this:

<authentication mode="Forms">
    <forms loginUrl="~/login.aspx" slidingExpiration="false" cookieless="AutoDetect" timeout="20" protection="All" enableCrossAppRedirects="false" defaultUrl="~/authenticated.aspx"></forms>

If you using some other mechanism e.g. some session based thing then you do this

Session.Abandon(); and then you can Response.Redirect("~/logn.aspx") i.e to you login page

More information is available on MSDN:



Jitendra Faye replied to Dom Afonso on 14-Sep-12 12:20 AM
for this you can set session Time out , This an be set In IIS or web.config file of your application.
Anandh Ramanujam replied to Dom Afonso on 18-Sep-12 10:04 AM
set sessiontimeout to 3 minutes in web.config