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
saljasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.