• Status: Open
  • Priority: Medium
  • Security: Public
  • Views: 28
  • 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
Thanks
0
saljas
Asked:
saljas
  • 3
  • 2
  • 2
7 Comments
 
Paul MacDonaldDirector, Information SystemsCommented:
You could use a javascript timer and reset it to your session timeout value every time the page refreshes.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
An ajax function could reset the session timer but the javascript timer would still remain the same, no?
0
 
Paul MacDonaldDirector, Information SystemsCommented:
@Kyle Probably, but that could be coded for as well.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
The best way is to read it directly from the session timeout on page_load().

https://msdn.microsoft.com/en-us/library/ms525473(v=vs.90).aspx

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.
0
 
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.
0
 
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>
<script>
    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)
        {
            document.location.reload();
        }
    }
</script>
1

Join & Write a Comment

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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