Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Hosting ASP.NET Outside IIS void CreateHost() { m_host = (Host) ApplicationHost.CreateApplicationHost( typeof(Host), vdirPath, filesPath); m_host.Configure(this, port, vdirPath, filesPath, _aspnetPath); } 791 Instances of the Server class are created in the Cassini AppDomain, whereas the Host object be- longs to the new AppDomain just created for the processing of HTTP requests. The Server object also provides a sort of public API to start, stop, and configure the Web server. The Cassini Web server sees this object as its unique point of contact with the ASP.NET back end. The Host class represents a remotable object and, as such, inherits from MarshalByRefObject . A remotable object is an object that can be called from within a different AppDomain. The Host class is responsible for opening a socket on the specified port and listens to incoming packets. When a request arrives and is accepted, the class creates a new Connection object to process the request. Connection conn = new Connection(this, (Socket) acceptedSocket); conn.ProcessOneRequest(); The Connection class receives the socket and starts working on the HTTP packets. The Connec- tion object is mostly an intermediary between the host and the actual worker request. The Connec- tion first creates the request object and then asks it to process the payload. Request req = new Request(host, this); req.Process(); The Request object derives from SimpleWorkerRequest . It examines the HTTP packet, extracts and preprocesses the message headers, and prepares the response buffer. When done, it simply hands the request out to the ProcessRequest method of the HttpRuntime object. While carrying out the request, ASP.NET calls back several methods on the Request object. In particular, all the data sent out through the Response object results in a call being made to one of the public methods of the host's worker Request object. The actual implementation of Cassini entails that the Request object passes this response data to the methods of the Connection object which, in turn, will route that through the open socket and the port. For this reason, an instance of the Connection object is passed to the constructor of the Request class. Cassini is the right tool for building serverless ASP.NET applications because it combines two key features: the ability to host the ASP.NET runtime to process .aspx requests and a simple, local-but- effective Web server infrastructure. With this structure, you don't need custom code running on top of the viewer to successfully process all page postbacks. Cassini is the missing link that now makes it possible to deliver entire Web sites on a CD and without the need of IIS. Put Your Web Site on a CD When I first examined Cassini, I created the following steps to test its overall effectiveness and make sure it was indeed a breakthrough in the building of offline Web applications. To begin, I stopped IIS and then launched the Cassini executable. (Note that to test Cassini, you must first stop IIS; otherwise, a conflict in accessing the port will occur.) Furthermore, Cassini processes only calls that go through http://localhost ; you can't access the local pages by using the machine name (for ex- ample, http://contoso), nor can you access Web pages on a Cassini-equipped machine from a re- mote machine. After that step, I opened Internet Explorer and typed http://localhost . To my great surprise, I was running my ASP.NET-based intranet without IIS! It goes without saying that if pages contain links to Internet Web sites, they will work as expected as long as an Internet connection is available.