Skip to content

Instantly share code, notes, and snippets.

@adrianvlupu
Created July 25, 2013 09:47
Show Gist options
  • Save adrianvlupu/6078325 to your computer and use it in GitHub Desktop.
Save adrianvlupu/6078325 to your computer and use it in GitHub Desktop.
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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment