Created
July 25, 2013 09:47
-
-
Save adrianvlupu/6078325 to your computer and use it in GitHub Desktop.
Ashx responding to a json POST body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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