Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Explore and Extend the Cassini Web Server

Extend the power of Cassini, Microsoft's source-available Web server based on the .NET Framework, to provide a lightweight HTTP server for your applications.


advertisement
TTP services are a core function for supporting many current application development technologies, including Web services, ASP.NET applications, and other traditional Web applications. The traditional way to provide HTTP support for Web applications on the Windows platform has been to run IIS. IIS has a number of problems however, including a history of security problems and some significant management issues. A viable alternative to using IIS is Cassini, Microsoft's source-available Web server platform written entirely in C#. Cassini supports ASP.NET and other basic functions such as directory browsing, and is compliant with HTTP 1.1. Cassini also demonstrates the power of the .NET Framework for building fully functional internet application servers. Even better, Cassini comes with source code enabling you to see the internal functions and modify it to suit your needs.

What You Need
You should have an understanding of the .NET Framework and C# or VB.NET. To build the sample project included with this article you need Visual Studio .NET and the .NET Framework SP1.

The basis for the Cassini implementation lies in the System.Web.Hosting namespace. This namespace contains the types that are core to the function of ASP.NET, and allow you to implement your own ASP.NET applications. Two of the important classes in this namespace are the ApplicationHost and the SimpleWorkerRequest. The ApplicationHost provides the ability to host ASP.NET applications outside of IIS. This is based on the ability of the ApplicationHost to create application domains that are used to process incoming ASP.NET requests. The SimpleWorkerRequest is derived from HttpWorkerRequest, and provides a simple implementation of the HttpWorkerRequest class to facilitate the processing of HTTP requests. The HttpRuntime class provides a ProcessRequest() method, taking the SimpleWorkerRequest as an argument. This is the core of ASP.NET request processing, and these classes are leveraged in the Cassini Web server.

You can use Cassini in a variety of ways. One that stands out is for ASP.NET development on machines that don't have IIS installed. The Cassini technologies form the basis for the Web server support in Microsoft's Web Matrix tool, which can run on Windows XP Home Edition software or other Windows systems (2000 or better) that don't have IIS installed. Cassini is also a great fit for building a small client application that's based on ASP.NET, such as a local browser-based training application. You can implement the Cassini Web server library in a custom GUI application that spawns a browser and processes HTTP requests locally. However, the software will not process remote requests as delivered—although you can change that in the Cassini source code if you like. As delivered, the following code prevents Cassini from responding to remote requests:



public void Process() { ... // Limit to local requests only if (!_conn.IsLocal) { _conn.WriteErrorAndClose(403); return; } }


The Request class of the Cassini server exposes a public Process() method, which validates the state of the connection as being local, and if not responds with a HTTP 403 error.

To best leverage Cassini as a learning and productivity tool, you can take advantage of the ability to extend its functionality. To demonstrate this, I will provide a brief technical overview of the Cassini source so you can see what's under the hood. Then I will demonstrate a custom feature extension to Cassini that will log all incoming connections and will add an entry to a log file. You'll review what's involved in building and debugging the source and consider some other possible application extensions for Cassini.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap