Jason Whitehorn

MarshalByRefObject.net
posts - 50, comments - 26, trackbacks - 6

My Links

News

Archives

Post Categories

.NET

Java

Proud Member Of...

XNA

An Embedded ASP.NET Web Server

UPDATE (12/17/2007): My blog has moved. This post is now located at: http://jason.whitehorn.ws/2007/06/21/An+Embedded+ASPNET+Web+Server.aspx




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.

Print | posted on Thursday, June 21, 2007 7:16 PM | Filed Under [ ASP.NET ]


Feedback

# Link Listing - June 21, 2007

Notepad2 V2 Released [Via: StevenCohn ] JetBrains Releases ReSharper 3.0 [Via: lkempe ] First Pretty... 6/21/2007 11:31 PM | Christopher Steen

Comments have been closed on this topic.

Powered by: