• Status: Open
  • Priority: Medium
  • Security: Public
  • Views: 43
  • Last Modified:

Displaying session Remaining time (in MM:SS) on a web page

using vb.net
How to display the session remaining time (in MM:SS) on a web page
  • 3
  • 2
  • 2
Paul MacDonaldDirector, Information SystemsCommented:
You could use a javascript timer and reset it to your session timeout value every time the page refreshes.
Kyle AbrahamsSenior .Net DeveloperCommented:
An ajax function could reset the session timer but the javascript timer would still remain the same, no?
Paul MacDonaldDirector, Information SystemsCommented:
@Kyle Probably, but that could be coded for as well.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

saljasAuthor Commented:
Mr Paul MacDonald and Mr Kyle Abrahams many thanks for your help.

I am looking for a code that gets the timeout from the page (not from web.config).

Many codes get timeout from (web.config), and if (web.config) timeout is set to 50 minutes and a line somewhere else is affecting that changing it to 2 minutes then there will not be a match between the displayed timeout counter (starting from 50) depending on (web.config) and the real timeout (starting from 2).

So in my opinion, obtaining timeout from the page and build a counter code depending on it is much better.

I have tried my best to explain my point, I hope it is clear.
Kyle AbrahamsSenior .Net DeveloperCommented:
The best way is to read it directly from the session timeout on page_load().


On every postback (non-ajax) the page_load will be invoked so that will be reset.

On AJAX the answer is "it depends".  If the subsequent call uses the session it will be refreshed, but if not (EG: a call to a web service that doesn't require session state) then I don't believe the timer is reset.
Paul MacDonaldDirector, Information SystemsCommented:
"I am looking for a code that gets the timeout from the page..."
The page has no idea what the timeout is.  That's a server-side thing.  When the page is refreshed, the timeout gets reset...on the server.  If you know what the time out value is, you can put code in the page to count down, but otherwise the page is completely ignorant of what's happening on the server.

There is a page refresh meta value, but that has nothing to do with the session.
saljasAuthor Commented:
After several days of experiments I think the following is doing fine, it can make session (looks like) last for ever, I do not know if I missed something but I hope I covered all possibilities, for three days, every morning I click on a button that transfer to another page and it works fine.
Always displaying the left seconds in the position of (DisplaySecLeft)
It reloads the current page every 3 hourse

The Page ends because of session timeout and idle timeout

1- session timeout can be set from web config
      <sessionState mode="InProc" timeout="120" />

2- idle timeout can be set from IIS manager, goto Control Panel
      >click System and Security
            >click Administrative Tools
                  >double-click Internet Information Services (IIS) Manager.
      then open the server branch and select (Applications Pools)
      select an the site in the list, and then click Advanced Settings... in the Actions column.
      In the Advanced Settings dialog box, under Process Model, change idle timeout to 120

In the asp page

<body background="../image/BGround1.Gif"  topmargin="0" leftmargin="0" onload="setInterval(myFunction, 1000)">
<p id="DisplaySecLeft">Time Left</p>
    var modal = document.getElementById('session-timeout');
    var sessionTimeOutValue = '<%= Session.Timeout * 60 %>';
    function myFunction() {
        sessionTimeOutValue -= 1;
        document.getElementById("DisplaySecLeft").innerHTML = sessionTimeOutValue; //displaying left sec
        if (sessionTimeOutValue < 10)

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now