Signout after a particular time [Resolved]

Posted by Nkkppp under ASP.NET on 8/24/2012 | Points: 10 | Views : 1493 | Status : [Member] | Replies : 7
I have a requirement where if the user has logged into the wbsite and stays IDLE for around 10mins..i need to redirect the user by loggin him out of the current session and go to the login page. But before moving to the login page i want to display a popup where a message is displayed like...within 3mins user session will expire....2mins...i.e. need to display a stopwatch for 10mins

Can nyone please share the code.

Thank you.




Responses

Posted by: Saratvaddilli on: 8/28/2012 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Check the following links,

http://stackoverflow.com/questions/709182/asp-net-implementing-auto-logout-functionality

http://www.codeproject.com/Answers/192202/Auto-logout-in-asp-net-csharp.aspx#answer5

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 8/25/2012 [Member] Silver | Points: 25

Up
0
Down
u can use timer control..

Regards,
Singaravel M

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 8/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

1. If you are using the authentication forms.
You can set the sliding expiration time="true" and timeout="10" as like here:

In web.config file:


<system.web>

<authentication mode="Forms">
<forms defaultUrl="~/default.aspx" loginUrl="~/LoginPage.aspx"
slidingExpiration="true" timeout="10" />
</authentication>

</system.web>


Regards,

Awesome Coding !! :)

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 8/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Vasanth.,

Thanks for the reply.

What bout the requirement where i need to display a popup box with the time left.

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 8/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

1. You can maintain a timer control and check event.

There might be several ways, as i am a beginner I tried this way. This might help you:

2. For a user, if we maintain a session as soon as he logs in and check current time from the logged in time as like:

In login page .cs file:

if(isAuthenticated == true) // log in credentials are authenticated.
{
session["TimeLoggedIn"] = DataTime.Now.ToShortTimeString();
}



Include the below thing under Page_Load or under a usercontrol and register it in the default or other pages you have in your website.


if(Session["TimeLoggedIn"] != null)
{

DateTime popup = (DateTIme.Parse((string)Session["TimeLoggedIn"])).AddMinutes(8); // Here im setting a check point i.e after 8 minutes i want to get a pop up window or msg.

if(DateTime.Parse(DateTime.Now.ToShortTimeString()) - DateTime.Parse(Session["TimeLoggedIn"].ToString()) >= (popup - DateTime.Parse(Session["TimeLoggedIn"].ToString())))

// Here, im checking if the difference (current time - the session started time) is >= (checkpoint time - session started time)
then a pop up window or message has to be displayed.

{

Response.write("You are left with only 2 min");
(OR)
//Include the Code here to raise a pop up window from codebehind.

}

}


If you dint find clarity, plz let me know.

Regards,

Awesome Coding !! :)

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 8/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Vasanth,

I will try it out and let u know.

Thanks.

Regards,
Prathap

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 8/28/2012 [Member] Starter | Points: 25

Up
0
Down
Thnq all for ur valuable time....i found 2-3 methods to do the same and working fine.

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response