Some time ago and again today, I had occasion to write an ASP.NET page that had no form in the .ASPX page but would accept and handle POST 'ed data. This was in an effort to support a REST-like interface for non-ASP.NET developers. Here's the way it turned out.
The .ASPX page looks something like this:
<%@ Page Language="C#"
There is nothing else in the file. Now the code behind looks like this:
public partial class extract : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string alldata = string.Empty;
using (StreamReader sr = new StreamReader(this.Request.InputStream))
alldata = sr.ReadToEnd();
//convert to strings - assumes URL encoded data
string pairs = alldata.Split('&');
NameValueCollection form = new NameValueCollection(pairs.Length);
foreach (string pair in pairs)
string keyvalue = pair.Split('=');
if (keyvalue.Length == 2)
if (alldata.Length > 0 && this.Request.HttpMethod.ToUpper() == "POST")
if (form["text"] != null)
//TODO - do something with the data here
Response.Write("*** 501 Invalid data ***");
Response.Write("*** 599 GET method not supported. ***");
Well, there you have it. There are probably better ways to do this, but I didn't find one.