Click here to Skip to main content
15,791,846 members
Articles / Programming Languages / XML

TinyWeb: A Simple Web Server in C#

Rate me:
Please Sign up or sign in to vote.
4.96/5 (20 votes)
11 Sep 2019CPOL1 min read 48.6K   2K   45   36
A simple home HTTP server that works across all .NET platforms


Note: This project only serves single requests at once. Try this one instead. It's better: Tiny Web Server Take 2


Currently, the offerings for .NET enabled web servers are platform dependent, and large, intended for scalable sites. Often, they have reams of features and lots of configuration. The simplest offering, http.sys, only works on windows.

The purpose of this web server is to expose a small, limited scalability server for something like a home network, or another scenario where the connection frequency is relatively low, and users are trusted.

It works on any .NET platform, and its component based API is simple to operate. Just drag it onto a form or a service component, wire up the events, and set the properties. Aside from the local endpoint to listen on, there is zero configuration.

Using the Code

Using the code is fairly simple:

using TinyWeb;
using System.Net;
var webServer = new WebServer(); 
webServer.ProcessRequest += new ProcessRequestEventHandler(webServer_ProcessRequest);
webServer.EndPoint = new IPEndPoint(IPAddress.Any,8080);
webServer.IsStarted = true;
void webServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
    var r = args.Response;
    r.ContentType = "text/html";
    r.WriteLine("<html><h1>Hello World!</h1></html>");

Request has methods for getting the headers, the querystring, and the request/post stream. Response has methods for setting the response headers, and for writing the response stream.

Points of Interest

SocketUtility contains many other methods for working with sockets, especially asynchronous socket communication, including exposing awaitable methods for the primary socket operations.


  • 28th August, 2019 - Initial submission


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
Just a shiny lil monster. Casts spells in C++. Mostly harmless.

Comments and Discussions

QuestionAnother option besides "rolling your own" Pin
gardner903230-Aug-19 12:35
gardner903230-Aug-19 12:35 
AnswerRe: Another option besides "rolling your own" Pin
Matt Slay30-Aug-19 16:44
Matt Slay30-Aug-19 16:44 
AnswerRe: Another option besides "rolling your own" Pin
honey the codewitch30-Aug-19 21:50
mvahoney the codewitch30-Aug-19 21:50 
GeneralRe: Another option besides "rolling your own" Pin
gardner903231-Aug-19 7:19
gardner903231-Aug-19 7:19 
GeneralRe: Another option besides "rolling your own" Pin
honey the codewitch31-Aug-19 7:21
mvahoney the codewitch31-Aug-19 7:21 
PraiseVery nice Pin
Michael Breeden30-Aug-19 9:04
Michael Breeden30-Aug-19 9:04 
BugRe: Very nice Pin
honey the codewitch11-Sep-19 7:30
mvahoney the codewitch11-Sep-19 7:30 
Praisethat's very useful,I give five Pin
Member 1457276229-Aug-19 22:22
Member 1457276229-Aug-19 22:22 
it can use in my current projects, thanks! btw, it's not perfect,for example, if you want to listen to all 80 ports, you can only open one process.

GeneralRe: that's very useful,I give five Pin
honey the codewitch30-Aug-19 4:52
mvahoney the codewitch30-Aug-19 4:52 
QuestionI like these sort of things Pin
Sacha Barber29-Aug-19 5:48
Sacha Barber29-Aug-19 5:48 
AnswerRe: I like these sort of things Pin
honey the codewitch29-Aug-19 7:36
mvahoney the codewitch29-Aug-19 7:36 
GeneralRe: I like these sort of things Pin
Sacha Barber30-Aug-19 2:03
Sacha Barber30-Aug-19 2:03 
GeneralRe: I like these sort of things Pin
honey the codewitch30-Aug-19 4:50
mvahoney the codewitch30-Aug-19 4:50 
GeneralRe: I like these sort of things Pin
Sacha Barber30-Aug-19 6:28
Sacha Barber30-Aug-19 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.