1

I have an application that allows users to upload audio files. On some very large files (1-2GB) I have run into an issue that the users session/authentication will time out, so when the file finishes uploading (which it does successfully) the user is forced to log in again.

I am using a third party tool called FileUploader on the front end and an ashx on the server side to handle the incoming file.

Does anyone have suggestions on how to keep the session/authentication from timing out while the file is uploading? Basically I would like the time that the file is being uploaded to be treated as if the user is actively using the site.

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
  • have a parallel ajax request to ping the server periodically while the upload is in progress? – Marc B Jul 02 '14 at 21:14
  • Or as another solution maybe just increase session timeout from 20 minutes to some bigger value? – Sergey Litvinov Jul 02 '14 at 21:16
  • @MarcB, That is an interesting idea. I assume that's something I would do from the client side? What would be a good way to do that? Perhaps fire a `GET` request from jquery that gets a tiny dummy HTML file? – Abe Miessler Jul 02 '14 at 21:21
  • Your session should only time out if there is a long period that lacks any HTTP activity. This may happen when your server is combining the chunks after all have been sent to the server. This combination process likely results in a long period of inactivity. If this describes your problem, please see http://stackoverflow.com/questions/23502554/server-timeout-when-re-assembling-the-uploaded-file. – Ray Nicholus Jul 02 '14 at 21:23
  • @RayNicholus, interesting, so are you saying that during the actual file upload, asp.net considers there to be HTTP activity, but once the file has been uploaded and is being processed on the server side there is no longer HTTP activity? – Abe Miessler Jul 02 '14 at 21:35
  • There is certainly HTTP activity during an upload. If chunking is enabled (I assume it is for such large files), your server will not respond to the last request by Fine Uploader, presumably, until all chunks are combined. This may take a while for large files split into small chunks. While Fine Uploader is waiting for this response, there is, of course, no HTTP activity (assuming nothing else is happening on the page). What is your timeout value set to? Are you seeing the timeout at the end of the upload? – Ray Nicholus Jul 02 '14 at 22:20
  • Well I have set my timeout to 1 minute for testing purposes. I know that this scenario will come up in the real world, but I don't want to wait 30 minutes each time I upload a file. I am seeing timeouts when the file finishes uploading from the browsers perspective. – Abe Miessler Jul 02 '14 at 22:47

1 Answers1

1

How about using FineUploader's progress event and make an Ajax call to a new WebService method that refreshes session every time progress is fired:

[System.Web.Script.Services.ScriptService]
public class SessionAlive : System.Web.Services.WebService
{

    [WebMethod]
    public void UpdateSession()
    {
        HttpContext.Current.Session["tempVariable"] = DateTime.Now;
    }
}

Or you could use a timeout that kicks off when the upload starts:

 $(document).ready(function() {
    setTimeout(updateSession, 1000*60);//Timeout is 1 min
});

function updateSession() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "SessionAlive.asmx/UpdateSession",
        data: "{}",
        dataType: "json"
    });
    setTimeout(updateSession, 1000 * 60);
}

Reference

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • 1
    One additional point which I discovered when looking for this solution. The WebMethod should be decorated with: [WebMethod(EnableSession=true)] – drdwilcox Oct 24 '16 at 21:56