0

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

Kelly
  • 1
  • 1
  • Try replacing IRequiresSessionState for IReadOnlySessionState http://stackoverflow.com/questions/2526168/asp-net-ihttpasynchandler-and-irequiressessionstate-not-working – Nikki9696 Mar 17 '16 at 15:38
  • doesn't make any difference, it behaves exactly as if it's IRequiresSessionState, thanks for trying to help – Kelly Mar 17 '16 at 16:17

1 Answers1

0

Just for reference, in case someone faced the same issue, it looks actually like a bug.

the answer of this question fixed the problem. I just added the a new module provided by the answer and it worked perfectly.

Uploadify ashx file Context.Session gets null

Kelly
  • 1
  • 1