C# WebServer


This project is a flexible http server which can be embedded in any .Net application. It has a modular design where features are added using modules. The server also supports REST and all http verbs (and not just GET). More info about the core: Core

The modular design allows you to use a small specific part or get a fully blown MVC webserver.
  1. Just use the (framework included, not System.Net.) HttpListener, to take care of everything yourself
  2. Use the httpserver, that also gives you better response handling and sessions.
  3. Add the file module, which also allows the server to serve files under a specific directory/subdirectories (you can also use multiple file modules).
  4. Add the controller module to be able to use controllers.
  5. Use the template manager in your controllers to get views.
  6. Use ViewController to integrate views in the controllers (adds some Render methods).

See? Modular design that doesn't force you to use more functions than you need.

Feel free to suggest new features, report bugs or give feedback

Please use the forum ("Discussions" tab) to ask questions, don't contact me directly. Others might be interested in the questions

Tutorial


Update
Tutorial 5 that is included in the source code (download latest revision) is a complete web application using validations, localizations, view controllers, embedded resources and models.

Current features

  • HTTP Basic and Digest authentication - The authentication process is activated either by throwing the UnauthorizedException or tagging controller methods with a special attribute.
  • Controllers ("C" in MVC)
  • Template engines ("V" in MVC)
  • Multiple web sites module (serve multiple websites in same server).
  • SSL Support
  • Multilingual applications
  • Validator - Validates input (got multilingual support)
  • Uniform input handling - Handle querystring/form/xml in the same way (you can add your own decoders too).
  • Helpers
  • Testing Simplified testing of controllers.

Upcoming features (not saying when ;)

  • Load balancing
  • Performance tuning
  • Reverse proxy (80% done)
  • Rewrite of the haml parser, to produce more beatiful html.

Example setup


            // Start with setting up the template engines we want to use.
            // There are currently two different template engines made, you can easily
            // create your own too.
            TemplateManager mgr = new TemplateManager();
            mgr.AddType(typeof(WebHelper)); // custom types are added so that they can be used in the templates
            mgr.AddType(typeof(ObjectForm));
 
            mgr.Add("haml", new HamlGenerator());
            mgr.Add("tiny", new TinyGenerator());
 
            HttpServer server = new HttpServer();
 
            // Add a rule that says that everyone that surfs to http://localhost:8081/ 
            // really wants to go to http://localhost:8081/widget/
            server.Add(new RedirectRule("/", "/widget/"));
 
            // Add the Controller Module since we want to use controllers
            // and views.
            ControllerModule mod = new ControllerModule();
 
            // browsing to http://localhost:8081/user/edit will invoke the method "public string Edit()" in  UserController.
            mod.Add(new UserController(mgr));
            mod.Add(new WidgetController(mgr));
            server.Add(mod);
 
            // The file module simply sends files to the browser (if they are found).
            FileModule fh = new FileModule("/", Environment.CurrentDirectory+ "\\public\\");
            fh.AddDefaultMimeTypes();
            server.Add(fh);
 
            // Let's start pure HTTP, we can also start a HTTPS listener.
            server.Start(IPAddress.Any, 8081);


This project is maintained by Gauffin Telecom AB, commercial support is available.
Last edited Oct 8 at 7:05 AM by jgauffin, version 46
Comments
No comments yet.

Updating...