Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Keeping the session alive

Keeping the session alive

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netsysadmintesting
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Talal Sultan
    wrote on last edited by
    #1

    Hello people, I'm having the following problem: I have a page where the user can upload a file for some processing. The file could be big (40 MB or more). I am using Rad Upload component and it is working well (with progress bar and all). Now the problem is that I cannot guarantee that all users around the world will have a fast internet connection and it could be possible that the upload time exceeds the timeout of the asp.net session. I have tried to use an Ajax timer with a code-behind event handler method in order to simulate a "ping". It works but once the upload starts, it stops. I have talked to Telerik about that and they said they have no way of making the upload do a ping. So now, I'm turning my attention more to the server code. Is there a way that I can keep alive the session in C#? My idea is to launch a thread when the user accesses the section where the upload is. That thread will keep on running with something in it to keep the session alive. And then when the upload completes and the postback is done, I would stop the thread. I haven't done any testing of this yet. I don't know if a session is kept alive if some code is being executed in it. I would also need to save the thread ID in the viewstate in order to be able to find it in the upload button event handler method. If anyone has some insight about this problem or maybe another way to solve this issue, I greatly appreciate your help. Thanks, Talal

    -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

    L S N 3 Replies Last reply
    0
    • T Talal Sultan

      Hello people, I'm having the following problem: I have a page where the user can upload a file for some processing. The file could be big (40 MB or more). I am using Rad Upload component and it is working well (with progress bar and all). Now the problem is that I cannot guarantee that all users around the world will have a fast internet connection and it could be possible that the upload time exceeds the timeout of the asp.net session. I have tried to use an Ajax timer with a code-behind event handler method in order to simulate a "ping". It works but once the upload starts, it stops. I have talked to Telerik about that and they said they have no way of making the upload do a ping. So now, I'm turning my attention more to the server code. Is there a way that I can keep alive the session in C#? My idea is to launch a thread when the user accesses the section where the upload is. That thread will keep on running with something in it to keep the session alive. And then when the upload completes and the postback is done, I would stop the thread. I haven't done any testing of this yet. I don't know if a session is kept alive if some code is being executed in it. I would also need to save the thread ID in the viewstate in order to be able to find it in the upload button event handler method. If anyone has some insight about this problem or maybe another way to solve this issue, I greatly appreciate your help. Thanks, Talal

      -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try using 1. Keep on updating Session variable during your server calls. To avoid session timeout. 2. Keep your session id in Hidden filed. If session expires then, same can be loaded from that field any time. 3. Increase to session timeout to the Worst case scenario scenario.

      T 1 Reply Last reply
      0
      • T Talal Sultan

        Hello people, I'm having the following problem: I have a page where the user can upload a file for some processing. The file could be big (40 MB or more). I am using Rad Upload component and it is working well (with progress bar and all). Now the problem is that I cannot guarantee that all users around the world will have a fast internet connection and it could be possible that the upload time exceeds the timeout of the asp.net session. I have tried to use an Ajax timer with a code-behind event handler method in order to simulate a "ping". It works but once the upload starts, it stops. I have talked to Telerik about that and they said they have no way of making the upload do a ping. So now, I'm turning my attention more to the server code. Is there a way that I can keep alive the session in C#? My idea is to launch a thread when the user accesses the section where the upload is. That thread will keep on running with something in it to keep the session alive. And then when the upload completes and the postback is done, I would stop the thread. I haven't done any testing of this yet. I don't know if a session is kept alive if some code is being executed in it. I would also need to save the thread ID in the viewstate in order to be able to find it in the upload button event handler method. If anyone has some insight about this problem or maybe another way to solve this issue, I greatly appreciate your help. Thanks, Talal

        -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

        S Offline
        S Offline
        Sundar_R
        wrote on last edited by
        #3

        Did you try setting the Server.ScriptTimeout property or scriptManager.AsyncPostBackTimeout if you are using a updatepanel.

        T 1 Reply Last reply
        0
        • L Lost User

          Try using 1. Keep on updating Session variable during your server calls. To avoid session timeout. 2. Keep your session id in Hidden filed. If session expires then, same can be loaded from that field any time. 3. Increase to session timeout to the Worst case scenario scenario.

          T Offline
          T Offline
          Talal Sultan
          wrote on last edited by
          #4

          Thank you for replying. I am trying to avoid increasing any timeout values and since it's the RAD component that is doing the upload in javascript, no server call is made until the upload is done, and this is precisely when it is timing out. If the session times out, the user is not more logged, I'm using Forms authentication. How would I get back all my Session variables?

          -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

          1 Reply Last reply
          0
          • S Sundar_R

            Did you try setting the Server.ScriptTimeout property or scriptManager.AsyncPostBackTimeout if you are using a updatepanel.

            T Offline
            T Offline
            Talal Sultan
            wrote on last edited by
            #5

            Thank you for your reply. It is important for me not to change any timeout values. It's a security requirement. Any idea if a thread is running on the server, will it keep the session alive or should we do a postback to keep it alive?

            -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

            S 1 Reply Last reply
            0
            • T Talal Sultan

              Thank you for your reply. It is important for me not to change any timeout values. It's a security requirement. Any idea if a thread is running on the server, will it keep the session alive or should we do a postback to keep it alive?

              -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

              S Offline
              S Offline
              Sundar_R
              wrote on last edited by
              #6

              Response will not be held until the thread method is finished. Even if the server timeout is reached, thread will continue its execution,it wont be clubbed with the page's life cycle execution. Using a thread might solve your problem,but you should think of many other scenarios like when to dispose your thread,when and where to check the thread status for disposal. Also keep in mind how many users simultaneously will try to do an upload. You might end up with serious memory leakage problems. These things might me costlier than the security requirement you try to maintain.

              T 1 Reply Last reply
              0
              • T Talal Sultan

                Hello people, I'm having the following problem: I have a page where the user can upload a file for some processing. The file could be big (40 MB or more). I am using Rad Upload component and it is working well (with progress bar and all). Now the problem is that I cannot guarantee that all users around the world will have a fast internet connection and it could be possible that the upload time exceeds the timeout of the asp.net session. I have tried to use an Ajax timer with a code-behind event handler method in order to simulate a "ping". It works but once the upload starts, it stops. I have talked to Telerik about that and they said they have no way of making the upload do a ping. So now, I'm turning my attention more to the server code. Is there a way that I can keep alive the session in C#? My idea is to launch a thread when the user accesses the section where the upload is. That thread will keep on running with something in it to keep the session alive. And then when the upload completes and the postback is done, I would stop the thread. I haven't done any testing of this yet. I don't know if a session is kept alive if some code is being executed in it. I would also need to save the thread ID in the viewstate in order to be able to find it in the upload button event handler method. If anyone has some insight about this problem or maybe another way to solve this issue, I greatly appreciate your help. Thanks, Talal

                -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

                N Offline
                N Offline
                NeverHeardOfMe
                wrote on last edited by
                #7

                A trick I use to keep the session alive on a particular page is as follows: Add the following to the body of your page (or add it via RegisterClientScriptBlock in Page_Load in code behind): function Reconnect(){ var img = new Image(1,1); img.src = '../common/reconnect.aspx'; } window.setInterval('Reconnect()',1170000); // 1170000 = (20 * 60000) - 30000 = 30s short of 20min, the default timeout having saved the follwing single line as reconnect.aspx <%@ OutputCache Location="None" VaryByParam="None" %> Works for me... the function Reconnect() gets called every 19.5 minutes, effectively pinging the server by calling nrecconect.aspx as the src of a 1x1px image... Hope this can help you..

                T 1 Reply Last reply
                0
                • S Sundar_R

                  Response will not be held until the thread method is finished. Even if the server timeout is reached, thread will continue its execution,it wont be clubbed with the page's life cycle execution. Using a thread might solve your problem,but you should think of many other scenarios like when to dispose your thread,when and where to check the thread status for disposal. Also keep in mind how many users simultaneously will try to do an upload. You might end up with serious memory leakage problems. These things might me costlier than the security requirement you try to maintain.

                  T Offline
                  T Offline
                  Talal Sultan
                  wrote on last edited by
                  #8

                  Thanks for your analysis. So basically I can try using this thread solution but I should to be careful of what will happen around it. I knew it would have other implications. I need to do a few tests now :) Thank you.

                  -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

                  1 Reply Last reply
                  0
                  • N NeverHeardOfMe

                    A trick I use to keep the session alive on a particular page is as follows: Add the following to the body of your page (or add it via RegisterClientScriptBlock in Page_Load in code behind): function Reconnect(){ var img = new Image(1,1); img.src = '../common/reconnect.aspx'; } window.setInterval('Reconnect()',1170000); // 1170000 = (20 * 60000) - 30000 = 30s short of 20min, the default timeout having saved the follwing single line as reconnect.aspx <%@ OutputCache Location="None" VaryByParam="None" %> Works for me... the function Reconnect() gets called every 19.5 minutes, effectively pinging the server by calling nrecconect.aspx as the src of a 1x1px image... Hope this can help you..

                    T Offline
                    T Offline
                    Talal Sultan
                    wrote on last edited by
                    #9

                    Thanks. I will try that, even though I am not sure it would work. You see, the problem I have is that Javascript is already running to upload the file and I have an Ajax timer set to postback every 6 sec (just for testing now). As soon as the upload starts, the timer stops working. So I suspect that only one Javascript code (or whatever) is executed and we cannot have multiple "threads" in Javascript executing at the same time. But I will try out your solution, maybe it would work since the javascript code (in the page) is executed once. I hope it would work :) Thank you

                    -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups