To correspond with the release of aspNETserve version 1.1, I have written a simple demonstration of hosting an ASP.NET 2.0 web server right into your own application.
The following code sample is about as simple as it gets.
using System; using System.Collections.Generic; using System.Text; using aspNETserve; namespace ConsoleWebServer { class Program { static void Main(string[] args) { string physicalPath = "c:\\wwwroot"; int port = 8080; using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", physicalPath, port)) { s.Start(); Console.WriteLine("Press any key to stop the server"); Console.ReadKey(); s.Stop(); } } } }
The aspNETserve namespace contains the Server object which represents an ASP.NET web server. The constructor of Server accepts an IPAddress to bind to, a virtual path, a physical path, and a TCP/IP port to listen on.
The above example will start a server at “http://localhost:8080/”. One of the nice things about this is that you can embed an ASP.NET web server right into your own application, without your users needing IIS installed on their machines.