I created an
HttpHandler
class in ASP.NET and configured a website to handle any request with the *.test path.
public class GameHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest (HttpContext context)
{
if (context.Request.ContentType == "application/json; charset=utf-8")
{
...
switch (parameters ["type"])
{
case "Setup":
result = Setup (context);
break;
case "DoStep":
result = DoStep (context, parameters);
break;
}
...
}
else
context.Response.Write (@"
<html>
<head>
</head>
<body>
<!-- some HTML -->
</body>
</html>");
}
In the
Setup
method I have such a code:
context.Session ["Game"] = new Game ();
In the
DoStep
method however,
context.Session.Count = 0
and
context.Session["Game"]
is NULL. I figured out that
context.Application
also loses the values that I put in it. In client side I use jquery to call these functions. Such a call looks like this:
$.ajax({
url: "/test.test",
type: "POST",
data: "{'type':'Setup'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {...}
});
$.ajax({
url: "/test.test",
type: "POST",
data: "{'type':'DoStep','row':'" + row + "','column':'" + column + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {...}
});
I suspect the problem is that ASP.NET doesn't know these requests sent from javascript belong to the same session and that's why the Session values are lost. I think that I would need to send back some cookie information or something for the next request to be identified but the fact is I don't have any idea.
Any help is really appreciated.