Reputation: 8889
What is the actual time of session timeout here is it 19 minutes ?
<%= Session.Timeout * 19 * 1000 %>
<script language="javascript" type="text/javascript">
setTimeout('SessionTimeout()', <%= Session.Timeout * 19 * 1000 %>);
function SessionTimeout() {
alert(<%= "'Session time out!!'" %>);
window.location = "Default.aspx"
}
</script>
Upvotes: 0
Views: 2117
Reputation: 26956
To clarify, is this what you're trying to do:
In JavaScript, 19 minutes after the user opens the page, you want to create an alert that warns the user that their session has timed out, and then redirect them to the Default.aspx page.
Then yes, as others have stated, the following should work for you:
<script language="javascript" type="text/javascript">
setTimeout('SessionTimeout()', 19 * 60 * 1000);
function SessionTimeout() {
alert(<%= "'Session time out!!'" %>);
window.location = "Default.aspx"
}
</script>
If you want this to be tied to the ASP.NET session timeout, and to be one minute less, then the following should work for you:
<script language="javascript" type="text/javascript">
setTimeout('SessionTimeout()', <%= Session.Timeout -1 %> * 60 * 1000);
function SessionTimeout() {
alert(<%= "'Session time out!!'" %>);
window.location = "Default.aspx"
}
</script>
Note however, that by doing it this way, if the user presses "OK" on the alert within 1 minute, they will still have an active session when they hit Default.aspx as the request will have happened within the timeout window, and will reset the clock.
Upvotes: 0
Reputation: 18586
Isnt this just getting the value? Followed by some maths.
Under IIS6 for Session.Timeout: The minimum allowed value is 1 minute and the maximum is 1440 minutes. The Default is 10 minutes
Source: http://msdn.microsoft.com/en-us/library/ms525473.aspx
While the DOCS say 10 - on testing the output of Session.Timeout the value returns 20.
Upvotes: 2
Reputation: 25810
Javascript setTimeout
takes in millisecond,
so to convert "Session.Timeout" to millisecond = Session.Timeout * 60 * 1000
Upvotes: 0
Reputation: 536379
Nope, it takes Session.Timeout
(which is measured in minutes) and converts it to an integer where each minute-unit corresponds to 19000. Assuming this ends up as a JavaScript time delta (which is measured in milliseconds), that maps each minute of timeout onto 19 seconds. Which is a bit odd.
Difficult to say why the code would be doing that without context. If the intent to output a JavaScript millisecond time delta representing the length of time Session.Timeout
does, it should read like:
var timeout= <%= Session.Timeout*60*1000 %>;
Upvotes: 0
Reputation: 1038780
The Timeout
property is expressed in minutes and is by default equal to 20 and is usually set in web.config:
<sessionState mode="InProc" cookieless="false" timeout="19" />
Upvotes: 1