5,442,164 members and growing! (17,441 online)
Email Password   helpLost your password?
General Programming » Internet / Network » HTTP / HTTPS     Intermediate

ASP Web Server

By Pablo van der Meer

This article presents a Web server with ASP support.
VC6, C++Windows, NT4, Win2K, WinXP, MFC, VS6, Visual Studio, Dev

Posted: 7 Jul 2003
Updated: 7 Jul 2003
Views: 94,969
Bookmarked: 62 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
29 votes for this Article.
Popularity: 6.66 Rating: 4.55 out of 5
1 vote, 3.4%
1
0 votes, 0.0%
2
3 votes, 10.3%
3
1 vote, 3.4%
4
24 votes, 82.8%
5

Description

This article presents a mini Web server with ASP support. When writing these classes I was inspired by an article from MSDN Magazine 'A Client-side Environment for ASP Pages ' by Dino Esposito. Although I didn't use any of the code from this MSDN article (mainly because it was written in VB) it was very helpful to get me started. One problem of Dino's solution is, that it is using the msscript.ocx (Microsoft Script Control), which is not available on all Windows system (you must download and install it separately from Internet Explorer). So in this article I present you a MFC solution that uses the Microsoft Scripting Engine COM interface.

Features

  • Multi threaded.
  • Real time server log.
  • Configure directory for web pages (same for all connections).
  • Configure default HTML page.
  • Support for GET, POST and HEAD methods.
  • Sends directory listing if default HTML is not found in directory.
  • Basic error handling (no custom messages yet).
  • ASP support (Request, Response, Server and Form collections)
  • Cookie support (including 'arrays' and enumeration!)
  • SSI (Server Side Includes) support

Known limitations

  • Most collections are case sensitive unlike real ASP collections!!!
  • Form and QueryString collections do not support arrays at this moment -> no list/combobox support
  • Application object not implemented
  • Session collection is not included. (but is available from my website).

Major classes used

CScriptEngine

This is a wrapper class around the COM interface of Microsoft's Scripting Engine. It simply converts all calls to the COM interface to easy to use MFC functions.

CAspParser

This class implements the ASP parser. It attaches the interfaces to the script engine and prepares the ASP page for execution. First all HTML code is converted to ASP code (Response.Write lines), so the resulting page contains only ASP code (= vbscript code). The Script Engine then executes this code and all output is written to the Response buffer. Any calls to Response or Request objects will be routed to my CResponseObject and CRequestObject classes. In the case of a web server this response buffer will be send back to the web browser.

CResponseObject

This class provides the IResponse interface to the scripting engine. The IReponse is used by ASP to write data from a script to the output HTML page. Only the most common used properties and methods are implemented.

CRequestObject

This class provides the IRequest interface to the scripting engine. The IRequest is used by ASP to read data from various collections into the script. The following collections are (partly) implemented:
  • QueryString Collection: used to get URL parameters.
  • Form Collection : used to get Form variables.
  • Server Variables Collection: used to get server information (local or remote ip address, server name and much more).
  • Cookies Collection: used to get data from cookies.

CCookie and CCookieEnum

Implementation of the ICookie interface to support cookies. This code is partly based the ATL class CCookie from Microsoft VC++ 7.0.

CCookieCollection and CCookieCollectionEnum

This is an attempt to duplicate the behaviour of the ASP IRequestDictionary interface to support cookies.

CListenSocket

This socket accepts all incoming connections. When a client connects to the server, CListenSocket accepts the connection and creates a new thread (CClientThread) that will take care of all further communication between the client and the server. After the thread has been created, CListenSocket will return to its waiting state.

CClientThread

This thread will handle all communication between the client and the server using CControlSocket.

CClientSocket

This socket class will process all incoming request and send back the response (files) to the client. All the other classes are just UI related.

Contacting the Author

Please send any comments or bug reports to me via email. For updates to this article (and many other articles), check my site: http://www.pablovandermeer.nl.

Revision history

  • July 4, 2004 - Initial revision.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pablo van der Meer


Pablo has been programming in C/C++ for 8 years and Visual C++/MFC for 6 years.
He is interested in music, blonde women and programming. His background includes telecommunication, electronics and software engineering, and he is currently based in 't Westland, The Netherlands.
Pablo van der Meer is developing software for a small Dutch telecom company. Besides programming Pablo is active as a dj/producer and creates various styles of music.

Check out my website for lots of other MFC articles:http://www.pablosoftwaresolutions.com

Occupation: Web Developer
Location: Netherlands Netherlands

Other popular Internet / Network articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 32 (Total in Forum: 32) (Refresh)FirstPrevNext
Subject  Author Date 
Generalreading cookies in vc++memberDhiraj kumar Saini21:03 30 Sep '07  
GeneralDownload filemembertrinh van hung20:47 2 Nov '06  
Jokegood , but exist one problem!memberJohnson88822:41 13 Feb '06  
GeneralRe: good , but exist one problem!memberPablo van der Meer22:59 13 Feb '06  
GeneralExquisite code and article ! SweetmemberDan Clark10:11 24 Jan '06  
GeneralCompilation errormemberdrjoju7:15 17 Aug '05  
GeneralCan we download webpages from URL containing https in any language.memberskyt0:49 9 Jun '04  
GeneralRequest Object is not BinaryRead methodmemberhandong21:24 4 Feb '04  
GeneralRe: Request Object is not BinaryRead methodmemberPablo van der Meer21:34 4 Feb '04  
GeneralQueryString bug?sussEugene Lin13:18 4 Jan '04  
GeneralRe: QueryString bug?memberPablo van der Meer22:45 4 Jan '04  
GeneralRe: QueryString bug?sussEugene Lin7:13 5 Jan '04  
Generalstatic linkmembermacrogu21:55 29 Oct '03  
GeneralRe: static linkmemberPablo van der Meer22:15 29 Oct '03  
GeneralThe Best!!!!memberGeorgi0:13 17 Oct '03  
GeneralSUPERMEN!memberNikolai Teofilov22:16 14 Sep '03  
Generalsample: how to connect to "index.html"memberRalph6:47 18 Aug '03  
GeneralRe: sample: how to connect to "index.html"memberAbhishek Tiwari19:51 25 Apr '06  
GeneralRe: sample: how to connect to "index.html"memberRalph22:02 25 Apr '06  
GeneralAn Excellent article.memberNeno_J23:56 26 Jul '03  
GeneralRe: An Excellent article.memberPablo van der Meer0:24 27 Jul '03  
GeneralMethod of connectionmemberCode4Food13:17 15 Jul '03  
GeneralRe: Method of connectionmemberPablo van der Meer4:53 16 Jul '03  
GeneralRe: Method of connectionmemberCode4Food5:07 16 Jul '03  
GeneralRe: Method of connectionmemberPablo van der Meer6:05 16 Jul '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Jul 2003
Editor: Nishant Sivakumar
Copyright 2003 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project