dimanche 28 juin 2015

session cleared on second ajax call

Here my problem is little weird, I encounter it only on my production server. Basically I loose session values on second ajax call. Whole process is like user clicks a button to initiate sync process, which involves two ajax hits, first a post request and on successful completion of this a second get request.

My code is like below:

jQuery Code:

//User clicks "SyncButton" to initiate sync process
    $('#SyncButton').on('click', function (event) {
        //Some UI Code
        $.ajax({
            type: 'POST',
            beforeSend: startService,   //startService has some UI code
            url: "FirstAjaxURL",
            data: null,
            contentType: "application/json",
            success: function (data) {
                ServiceSuccess(data);
            },
            error: serviceError
        });
    });

function ServiceSuccess(data) {
    var html = ''; //code to get html from data
    $('#divSync').html(html);
    if (!($('#delete').length > 0)) {
        RenderBusinessGrid();
    }
};

function RenderBusinessGrid() {
    var allBusiness = "";
    $.getJSON("SecondAjaxURL", function (data) {
        //Some UI handling code
    });
    $('#divSyncDetails').height('400px');
}

MVC code:

[HttpPost]
public string FirstAjaxURL()
{
    //make some DB hits
    //fetch data
    //create couple of zip files
    //save them in two separate folders in separate folders under root directory

    /*LOGS SUGGEST ALL SESSION KEYS WERE AVAILABLE HERE*/
    return "some string result";
}

public ActionResult SecondAjaxURL()
{
    /*LOGS SUGGEST SESSION KEYS NOT AVAILABLE HERE*/

    //do some DB operation 
    return jsonResult;
}

What all I have tried so far:

  1. Checked IIS settings for application pool recycle time, they seem to be fine
  2. Session timeout is set to large value, it doesn't timesout if I leave system for idle
  3. Confirmed there's no unhandled exception in first ajax hit
  4. Tried saving zip files outside application's directory structure
  5. Tried replacing $.getJson with $.ajax(I know its stupid to try this but you never know... :)

Note: In majority of cases session timesout on second ajax call the very first time user initiates the sync process. While we observed quite some cases where this happens second or third time.

Please suggest what else I could try/verify to get root-cause of this issue, its bugging me big time. All pointers are welcome.

Thanks, Ravi

Aucun commentaire:

Enregistrer un commentaire