.NET, Archive, ASP.NET, aspNETserve, C#
     

An Embedded ASP.NET Web Server

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.

Never miss an article! Subscribe to my newsletter and I'll keep you updated with the latest content.

 

About Jason

Jason is an experienced entrepreneur & software developer skilled in leadership, mobile development, data synchronization, and SaaS architecture. He earned his Bachelor of Science (B.S.) in Computer Science from Arkansas State University.
View all posts by Jason →

Leave a Reply

Your email address will not be published. Required fields are marked *