The idea is simple. Use server side code to populate the DOM with the current Session timeout value on each request. The JavaScript app uses this value to setup the timer.
As always, post your code. Explain what you expect to happen and what actually happens. Include any error messages.
How can I force a redirect on the client that is the same length as the session time-out by using a client script?
According to your description, I suggest you could firstly get the session timeout value when page load, then you could use javascript setInterval function to redirect user to login page.
More details, you could refer to below ASP.NET example:
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
The session is not reseted automatically on each postback.
What happenes now is that the user is asked to reset the session after it's timeout, even if he keeps working with the system and posting back to the server.
Doesn't it suppose to reset it whenecer the user keeps posting back to the server?
My main purpose is to prevent situations when users doesn't log out of the system and someone can view sensitive data that was left open.
The session is not reseted automatically on each postback.
What happenes now is that the user is asked to reset the session after it's timeout, even if he keeps working with the system and posting back to the server.
Doesn't it suppose to reset it whenecer the user keeps posting back to the server?
As far as I know, the session expired time will refresh when the user access page again.
Normally we should reget the session.timeout value, if user postback the page.
I suggest you could directly using below codes to reset the count after user accessed page again.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
53 Points
275 Posts
Force redirect on the client
Sep 04, 2018 10:39 AM|qsoft_developer|LINK
How can I force a redirect on the client that is the same length as the session time-out by using a client script?
All-Star
53131 Points
23682 Posts
Re: Force redirect on the client
Sep 04, 2018 10:52 AM|mgebhard|LINK
Use one of the JavaScript timer functions. Also, this is well covered subject that a basic Google search will reveal.
https://www.w3schools.com/howto/howto_js_countdown.asp
The idea is simple. Use server side code to populate the DOM with the current Session timeout value on each request. The JavaScript app uses this value to setup the timer.
As always, post your code. Explain what you expect to happen and what actually happens. Include any error messages.
All-Star
54508 Points
14111 Posts
Re: Force redirect on the client
Sep 04, 2018 11:57 AM|mudassarkhan|LINK
Refer
Automatically redirect User after Session Timeout in ASP.Net
Blog: ASPSnippets | Forum: ASPForums | Company: Excelasoft
Star
9831 Points
3120 Posts
Re: Force redirect on the client
Sep 05, 2018 06:31 AM|Brando ZWZ|LINK
Hi qsoft_developer,
According to your description, I suggest you could firstly get the session timeout value when page load, then you could use javascript setInterval function to redirect user to login page.
More details, you could refer to below ASP.NET example:
Auto redirect to login page when Session is expired
Best Regards,
Brando
Member
53 Points
275 Posts
Re: Force redirect on the client
Sep 12, 2018 08:17 AM|qsoft_developer|LINK
Hi mudassarkhan,
I tried using your solution. Can you please explain why there is a check for IsPostback on the Page_Load?
The session is not reseted automatically on each postback.
What happenes now is that the user is asked to reset the session after it's timeout, even if he keeps working with the system and posting back to the server.
Doesn't it suppose to reset it whenecer the user keeps posting back to the server?
My main purpose is to prevent situations when users doesn't log out of the system and someone can view sensitive data that was left open.
Star
9831 Points
3120 Posts
Re: Force redirect on the client
Sep 19, 2018 06:44 AM|Brando ZWZ|LINK
Hi qsoft_developer,
As far as I know, the session expired time will refresh when the user access page again.
Normally we should reget the session.timeout value, if user postback the page.
I suggest you could directly using below codes to reset the count after user accessed page again.
Best Regards,
Brando
All-Star
54508 Points
14111 Posts
Re: Force redirect on the client
Sep 19, 2018 03:00 PM|mudassarkhan|LINK
This was an Article requirement. If you closely see, in my case I am doing redirect from JavaScript and hence I have added the condition.
In your case, if it is not needed, it can be removed.
Blog: ASPSnippets | Forum: ASPForums | Company: Excelasoft
Member
53 Points
275 Posts
Re: Force redirect on the client
Sep 20, 2018 06:32 AM|qsoft_developer|LINK
Thanks for your reply.
I tried removing the condition as suggested, but I still don't get the expected results.
It doesn't mattaer how many times I post back to the server, I receive the alert message after 1 minute.
Any idea what I'm doing wrong?
I can see the following code in view source:
Member
53 Points
275 Posts
Re: Force redirect on the client
Sep 20, 2018 07:05 AM|qsoft_developer|LINK
Ok, I think I figured out what is going on here.
I added all the code to the master page and I expected the session to be reseted on each postback of the content page.
I still don't understand why it's not working. I can see the masterpage code is suppose to run on each postback.