keeg keeg - 5 months ago 32
C# Question

how to setup a .net standalone app that creates and hosts a website on localhost

I have a program (.exe) file that creates a website on localhost:8080 and it opens up a bunch of commands that can be executed by going to various urls on the website. I'm not sure what this is written it, but I'm wondering if its possible to do in .net (c#). Where I launch a self contained .exe file (that will used an embedded database) and I can write to the database via the website that is created on localhost.

So basically I want the website to serve as the GUI for a standalone .exe file.


Yes, this is quite easy using an HttpListener.

As an example to help you do more, grab the class from the link below, then you can just stick this into a simple console app, run it and go to http://localhost:8080/test/

static void Main(string[] args)
    WebServer ws = new WebServer(SendResponse, "http://localhost:8080/test/");
    Console.WriteLine("A simple webserver. Press a key to quit.");

public static string SendResponse(HttpListenerRequest request)
    return string.Format("<HTML><BODY>My web page.<br>{0}</BODY></HTML>", DateTime.Now);    

There is more code here under the MIT license: Copyright (c) 2013 David's Blog (