adrianvlupu
7/25/2013 - 9:47 AM

Ashx responding to a json POST body

Ashx responding to a json POST body

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OAuth;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace TheHashProject
{
    public class Ajax : IHttpHandler
    {
        private HttpContext context;
        public void ProcessRequest(HttpContext context)
        {
            this.context = context;
            context.Response.ContentType = "application/json";
            string req = new StreamReader(context.Request.InputStream).ReadToEnd();
            if (!String.IsNullOrEmpty(req))
            {
                JObject jsonRequest = JObject.Parse(req);

                Response(new{name="lupu"});
            }
        }

        public void Response(object obj)
        {
            context.Response.Write(JsonConvert.SerializeObject(obj, Formatting.None).ToString());
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}