Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.net MVC session timeout duration

Posted on 2017-08-16
3
Low Priority
?
128 Views
Last Modified: 2017-08-21
Perhaps I am over-thinking this but what I need to do is see what the time difference it is from the start session time (1 minute) subtracting the current time.
<script type="text/javascript">
var mySessionTimer;

@functions {        
    public int PopupShowDelay
    {
        get {
            DateTime currentSetTimeout = DateTime.Now.AddMinutes(HttpContext.Current.Session.Timeout);
            DateTime currentServerTime = DateTime.Now;
            TimeSpan duration = (currentServerTime.Subtract(currentSetTimeout));

            return 60000 * (int)duration.TotalMinutes;
        }
    }
}

function callJSSessionTimer() {
    var sessionTimeoutWarning = @PopupShowDelay;
    var sTimeout = parseInt(sessionTimeoutWarning);

    mySessionTimer = setTimeout('SessionEnd()', sTimeout);
}

function SessionEnd() {
    clearTimeout(mySessionTimer);
    window.location = "/Account/sessionover";
}

@if (userInfo != null)
{
    if (userInfo.chosenAMT == "True")
    {
        @:callJSSessionTimer();
    } else
    {
        @:clearTimeout(mySessionTimer);
    }
} else {
    @:clearTimeout(mySessionTimer);
}
</script>

Open in new window

So for the value for duration is -00:01:00 which technically is correct since currentSetTimeout is 1 minute and it gets todays date/time which is a minute away since its subtracting it fromcurrentSetTimeout.

So the point of all of this is to keep track of the remaining session time when the user jumps from page to page. Currently when the user goes to another page, it resets the time and its not accurate.

How can I go about doing this the way I need it?
0
Comment
Question by:Stealthrt
  • 2
3 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 42257486
when user request anything from server, session timeout is reset on server...
what are you trying to do here?
0
 

Accepted Solution

by:
Stealthrt earned 0 total points
ID: 42257700
Got it...
@functions {        
        public int PopupShowDelay
        {
            get {
                if (Session["currentSetTimeout"] != null)
                {
                    DateTime dt1 = DateTime.Parse(Session["currentSetTimeout"].ToString());
                    DateTime dt2 = DateTime.Parse(DateTime.Now.ToString());
                    TimeSpan span = dt1 - dt2;
                    
                    return (int)span.TotalMilliseconds;
                }

                return 0;
            }
        }
    }

Open in new window

0
 

Author Closing Comment

by:Stealthrt
ID: 42263102
Figured it out myself.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question