I'm testing the Azure server with pages that use Ajax(json)/Webmethod functions.
Some of those functions check HttpContext.Current.User.Identity.IsAuthenticated
before they run code. Unfortunately, if a user is logged in and the page doesn't make a full postback request to the server, only those webmethods functions that check HttpContext.Current.User.Identity.IsAuthenticated
stop running completely after couple of minutes without giving any error. They don't even run the else
code block (see below).
I've tested those pages on a local server and everything worked fine as it should, even after a long period of inactivity. Here is an example of a webmethod
[WebMethod]
public static string serviceMenu(int IDservice)
{
StringBuilder SBphotoMenu = new StringBuilder();
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
// Do stuff
}
else
{
// Do other stuff
}
return SBphotoMenu.ToString();
}
I'm calling the webmethod as follows:
function serviceMenu(IDservice) {
$.ajax({
type: "POST",
url: "/UserControls/serviceMenu",
data: "{ IDservice: " + IDservice }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Do Stuff
}
})
}
This behavior occurs only if the user is logged in. Now if the user is not logged in then all functions work properly even on Azure.
As a matter of fact, when the webmethods stop running and I refresh the page the user is still logged in and the webmethods start running again but for couple of minutes only and then the same behavior occurs again.
What's going wrong?
The problem is caused by the session variables and not autentication. In fact the session state is not maitained for ASP.NET applications in Azure using the default "inProc" method. Azure uses other methods, of which some are costy: Table storage, SQL Azure, or Windows Azure Caching.