Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 27,881 times

Contents

Downloads

Related Categories

Create your own Web Server using C# - Configuration

Imtiaz Alam

Configuration

First we will define the root folder for our web server. Eg: C:\MyPersonalwebServer, and will create a Data directory underneath, our root directory Eg: C:\MyPersonalwebServer\Data. We will Create three files under data directory i.e.

Mimes.Dat
Vdirs.Dat
Default.Dat

Mime.Dat will have the mime type supported by our web server, Syntax:  <EXTENSION>; <MIME Type>e.g.
.html; text/html
.htm; text/html
.gif; image/gif
.bmp; image/bmp

VDirs.Dat will have the virtual directory Information. Syntax: <VirtualDir>; <PhysicalDir>  e.g.
/; C:\myWebServerRoot/
/test/; C:\myWebServerRoot\Imtiaz\

Note: We have to include all the directories used by our web server, for example, if the html page contains reference to images and we want to display image, we need to include it also. e.g.
/images/; c:myWebServerRoot\Images\, else that directory won't be accessed..

Default.Dat will have the virtual directory Information; e.g.
default.html
default.htm
Index.html
Index.htm;

We will store all the information in plain text file for simplicity, we can use XML, registry or even hard code it. Before proceeding to our code let us first look the header information which browser will pass while requesting for our web site

Let say we request for test.html we type http://localhost:5050/test.html
(Remember to include port in the url), here what the web server gets..

GET /test.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: en-usAccept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; .NET CLR 1.0.2914)
Host: localhost:5050
Connection: Keep-Alive

Imtiaz Alam is a Senior Developer, currently residing in Phoenix, Arizona. He has more than five years of development experience in developing Mirosoft based Solution.

Imtiaz Alam is a Senior Developer, currently residing in Phoenix, Arizona. He has more than five years of development experience in developing Mirosoft based Solution. He can be reached at alamimtiaz@hotmail.com

Comments

  • Re: [1775] Create your own Web Server using C#

    Posted by michemal on 22 Jun 2007

    I was looking for a web server and came across a couple of other
    options, of course there is cassni / aka webdev but i tried this http://www.neokernel.com serv...

  • compression?

    Posted by rahulgarware on 01 Dec 2005

    How do you extend this to enable HTTP data compression?
    header:
    content-encoding=gzip

  • No Entry Point

    Posted by Aschehoug on 29 Jul 2005

    This code has no entry point. When compiling, I only get "error CS5001: Program 'c:\MyWebServer\MyWebServer.exe' does not have an entry point defined". I know that it is looking for a "Main()", but I ...

  • Posted by Michael H on 07 Sep 2004

    Hehe, I moved permanently to C# only a month or 2 after
    creating this thread :).

    I now have trouble reading VB code. Array access looks like
    function calls, etc... :cool:

  • Posted by SErhio on 07 Sep 2004

    i find c# more comprehensible then VB.
    for a C# programmer is more difficult for read VB code...