I would like to submit some data using HTTP POST method to an asp.net HttpHandler(.ashx)
I am confused, as I can use the GET method and it works properly, but the handler I am trying to create has to use the POST method.
my Jquery code:
$.post(this.getUrl(), this.parameters, function (data, textStatus) {
//code
}, "json");
I am sure about the URL and I send a JSON object in the parameters.
my C# generic handler
public class ghandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write(HttpContext.Current.Request.Form["action"]);
}
public bool IsReusable
{
get
{
return false;
}
}
}
I implemented IRequiresSessionState as I need to have a read/write access to the session. At this point, the sessions work, but the HttpContext.Current.Request.Form doesn't, actually I have been debugging this for a while, the Jquery doesn't post the data for some reason, so the problem is probably in the Jquery code.
What's driving me crazy more is that if I don't implement the IRequiresSessionState interface, the post works!! but I lose the sessions for sure.
note: as I mensioned above, using the IRequiresSessionState, my JQuery doesn't even post the data, I checked that using Chrome DevTools -> Network -> my request -> Headers -> Form Data
the form data doesn't exists if I implement the IRequiresSessionState