Home > Uncategorized > Open Source Pastebin in .NET

Open Source Pastebin in .NET

A pastebin is designed to be an easy way to quickly post some text online, so that others can see it. It also has applications in cross-firewall data traversal, where one peer can upload data to a pastebin, and the other peer can poll the pastebin for the message to arrive.  This was the kind of pastebin I was after.

I looked at pastebin.com and paste.kde.org, to see if they were suitable. Paste.kde.org seemed promising,  where you could paste easily, using a URL like this:


Which would return an ID, which you could retrieve using http://paste.kde.org/api/xml/117613, for example. The problem came, when I wanted to list all pastes by a particular user, or project, and I spotted that it wasn’t working as expected, like http://paste.kde.org/~fiachspastebin/api/xml/all/ seemed to return numerous pastes by other users.

So, I decided to write my own pastebin, which would store the messages in-memory. This meant that they would be deleted as the IIS worker process recycled, but, I didn’t need longevity.

Using two simple actions “action=update” which either created or updated a paste, and assigned it to a “user“, containing the text contained in the “text” querystring parameter. Then when “action=get” then the text associated with that “user” would be returned.

So, to store text with a user, you simply call:


Then to retrieve that text you call


And that’s it. The code I used is below:

  public static Hashtable data = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
        string action = Request.QueryString["Action"];
        string user = Request.QueryString["User"];
        string text = Request.QueryString["Text"];
        if (string.IsNullOrEmpty(action) || string.IsNullOrEmpty(user))
            Response.Write("Action and User is required");
        if (action == "update")
            PasteBin.data[user] = text;
        if (action == "get")
            if (PasteBin.data.ContainsKey(user))
                Response.Write("NO DATA");

I’ve ported the same code to PHP, for Linux users. This code requires the $_APP library, which is posted at http://www.leosingleton.com/projects/code/phpapp/

This is hosted at http://pastebin.omadataobjects.com/bin.php

$action = $_REQUEST["action"];
$user = $_REQUEST["user"];
$text = $_REQUEST["text"];
if ($action == "" || $user == "")
   echo("action and user is required");
   if ($action=="update")
	$_APP[$user] = $text;
	echo "OK";
   if ($action=="get")
	echo stripslashes($_APP[$user]);
Categories: Uncategorized
  1. August 22, 2015 at 1:22 pm

    I added an extra function to the PHP version as follows;

    if ($action==”log”)
    $_APP[$user] .= $_SERVER[‘REMOTE_ADDR’] . ‘ ‘ . date(‘Y-m-d H:i:s’) . ‘ ‘ . $text . ‘
    echo “OK”;

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: