0

I'm working on an e-commerce site, Some of the information to identify the user are stored in session variables.

What happens is that if customer logs in at 16:00 and session variables have a timeout of two hours ,At 18:00, no matter what he is doing, he will be disconnected.

This could create problems for the client while he is making an order.

Even extending the lifetime of variables to 8 hours, there is the possibility that the client reconnects at 23:55 (almost 8 hours after 16:00) and he will be disconnected after only 5 minutes of browsing.

What I'm trying to find out is if there is a way to extend the duration of the current session for each connection.

For example: (It is assumed that on each page there is the code to extend the duration of the session)

the session expires every 30 minutes.

user1 connects at 16:00.

the session will expire at 16:30.

user1 enters the shopping cart page at 16:02

the session will expire at 16:32.

user1 enters the home page at 16:04

the session will expire at 16:34.

and so on ..

if user1 does not open any page for 30 minutes will be disconnected.

Currently I built the whole system in vb.net and I was able to extend the duration of the session variables (only starting from the first variable declaration) with the command Session.Timeout = 60 But I could not find a way to dynamically extend it.

Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32
benVG
  • 603
  • 3
  • 14
  • 25
  • see msdn [Using ASP.NET Session State](http://msdn.microsoft.com/en-us/library/ms972429.aspx) – Grundy Dec 12 '13 at 12:18

2 Answers2

1

Change your web.config. GIve your desired time as the value for timeout field.

<sessionState 
    mode = "[Off|InProc|StateServer|SQLServer|Custom]"
    timeout = "yourTimeHere">
</sessionState>
Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32
1

If I understand your need ,you want to extend the session as long as the client's browser is open.

you have to make a ajax call to asp.net page every few minths to renew the session.

something like this

    function keepSession() {
        setTimeout("callWebService()", 60000); // every 1 min
    }

    function callWebService() {//call httphandler ,webservice or aspx page
        $.ajax({
                url: "/WebServices/keepSession.svc/keepSession",
                // The key needs to match your method's input parameter (case-sensitive).
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
});

    }

in this case You don't need to worry about session timeout at all.

In addition, I recommend keeping the session in sql mode because it's very fragile in InProc mode.

baaroz
  • 19,119
  • 7
  • 37
  • 47
  • is a very interesting suggestion to use this procedure with ajax! I had not thought of that! – benVG Dec 12 '13 at 12:45
  • 1
    I had the same problem when I built e-commerce ,you mast keep the session in sql mode for a start,and by calling server method throw ajax the session will keep a live as long as the browser is open – baaroz Dec 12 '13 at 12:52
  • is an interesting vision of the "make dynamic", but currently my customer wants to disconnect the user after a period of inactivity, it does not matter if you have the page open. Anyway you gave me a great idea for future use! – benVG Dec 12 '13 at 12:58