Reputation: 1427
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
EDIT 6 July, 2015
//Unzip a zip file in one of the sub-directories. This zip file contains multiple sub-directories and files.
EDIT 6 July, 2015
//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:
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.
Some further details: I checked event logs and found that every time it logs out below error is logged in event viewer:
Event code: 4005 Event message: Forms authentication failed for the request. Reason: The ticket supplied was invalid.
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
Upvotes: 4
Views: 1584
Reputation: 1427
My issue in brief: In first ajax some operations were performed which include add/update multiple file/folders and second ajax hit that is initiated once result of first reaches client fail due to unavailability of session variables.
Root cause: File Change Notification (FCN) behavior
Solution: In my case I ended up moving the culprit folder where all file/folder changes were occurring outside the web app. Since I needed direct access of files of this folder from web app, I ended up making this folder as a virtual directory.
So previously it was like this
and now it looks like this with my actual asset folder sitting outside my webapp with its own virtual directory and separate app pool to mess around with :)
Note: I tried using FCNMode web.config setting that seems to have worked for some users on .NET 4.5 but unfortunately it didn't worked for me. If you are facing a similar problem, I'll suggest to try that setting first.
Upvotes: 0
Reputation: 263
I had a similar problem a few years ago. The problem I had is similar to What could cause an asp.net application to forget a user?.
The key is in the author's own answer: The problem seems to be that the app pool is recycling and the authentication cookie becomes invalid because it can no longer be read as the machine key has changed. The solution was to add a machineKey segment to the web.config and supply a static machine key.
Upvotes: 1