views:

285

answers:

6

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>
+1  A: 

I don't beleive Session.Timeout is being set there, only get.

Gregory
+2  A: 

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.

Pino
Yes `<%=` writes the value out
pjp
Default session timeout is 20 min.
Muhammad Akhtar
http://msdn.microsoft.com/en-us/library/ms525473.aspx - I read 10 thats the main reason for the 10 minutes. I may however be completley wrong.
Pino
i have edited the question
The default value of HttpSessionState.Timeout *is* 20: http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.timeout.aspx You're looking at the default Session timeout from ASP.
Zhaph - Ben Duguid
+1  A: 

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" />
Darin Dimitrov
Is the default not 10 minutes? - http://msdn.microsoft.com/en-us/library/ms525473.aspx
Pino
I created a new ASP.NET application (.NET 3.5 SP1) and printed the value of Session.Timeout and it was 20.
Darin Dimitrov
Fair play, interesting to know why that is.
Pino
A: 

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 %>;
bobince
please see the edited question
Yeah, I'm pretty sure that's a mistake. It should be *60, not *19.
bobince
ok..how can i set it to 19 minutes ?
@SmartestVEGA: You have to set it at the server-side script. Not for the client-side JS.
o.k.w
i want to set timeout for 19 second in javascript is it possible by editing this code?
Well you can say `setTimeout(SessionTimeout, 19*1000)`, sure, but it doesn't change the real (server-side) timeout. The user will just be sent to the `Default.aspx` page but will still be in the same session. The ASP.NET Session.Timeout can only be set in minutes so you can't have a timeout as (insanely!) short as 19 seconds.
bobince
A: 

Javascript setTimeout takes in millisecond,
so to convert "Session.Timeout" to millisecond = Session.Timeout * 60 * 1000

o.k.w
i want to set timeout for 19 second in javascript is it possible by editing this code?
A: 

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.

Zhaph - Ben Duguid