170 likes | 377 Views
Hosting ASP.NET. Ted Neward Neward & Associates blogs.tedneward.com. Credentials. Who is this guy? Independent consultant Author C# in a Nutshell (O’Reilly, with Drayton, Albahari, 2001) Server-Based Java Programming (Manning, 2000)
E N D
Hosting ASP.NET Ted NewardNeward & Associatesblogs.tedneward.com
Credentials • Who is this guy? • Independent consultant • Author • C# in a Nutshell (O’Reilly, with Drayton, Albahari, 2001) • Server-Based Java Programming (Manning, 2000) • SSCLI Essentials (O’Reilly, with Stutz, Shilling, 2003) • Effective Enterprise Java (Addison-Wesley, 3Q 2003) • Papers at http://www.neward.net • Blog at http://blogs.tedneward.com
A Brief History • HTTP takes over the world • HTTP & HTML used to be synonymous • CGI begins the “dynamic HTML” approach • ISAPI becomes a “lighterweight CGI” • ASP becomes higher-level ISAPI • And everybody lived happily ever after
A Brief History, part II • Well, OK, not that last part • ASP is nice, but has some flaws • Robustness: in-proc approach (at first) • HTTP “changed”, or what we expect of it did • IIS presents some issues, too
Issues • Current dependency on IIS has issues • IIS is “more” than just HTTP • WebServices want to keep overhead “light” • IIS represents huge security liability • ASP, for all its goodness, is “tied” to IIS • ASP really isn’t using IIS all that much • ASP depends on COM—apartments, etc
ASP.NET • Latest release of ASP • Also known as the “HttpRuntime” • Provides managed extensions to HTTP • .ASPX pages == content-driven response • .ASHX pages == code-driven response • .ASMX pages == WebServices-driven • All behind IIS?
HttpRuntime • HttpRuntime entirely divorced from IIS • Cassini (part of Saturn): C# HTTP Server • Hosts HttpRuntime directly—no IIS! • Key: System.Web.Hosting namespace
System.Web.Hosting • Underdocumented API for HttpRuntime • Create HttpRuntime AppDomain • ApplicationHost.CreateApplicationHost(…) • Pass HttpWorkerRequest into host • Key lies in HttpRuntime.ProcessRequest()
Minimal Host • Barebones HttpRuntime host:
Minimal Host • Run by passing “requests” on cmd line
Implementation • What’s going on here? • CreateHost spins off new AppDomain • Host must be MarshalByRefObject as a result • Host lives in new AppDomain instance • Multiple hosts, multiple AppDomains • Host configured with physical dir and URL “path”
Implementation • Once host is created • Host must somehow receive request • Host’s responsibilities: • Call HttpRuntime.ProcessRequest • Pass in a HttpWorkerRequest-implementing object • Object contains parameters to request • SimpleWorkerRequest a simple example • HttpRuntime takes over from here • Complete support: web.config, handlers, etc
HttpWorkerRequest • Class representing request/response • Host’s responsibility for extracting all info • SimpleWorkerRequest provides basic info • Real-world implementation would extract data from port, etc. • Also provides response buffer for output • SimpleWorkerRequest uses TextWriter passed in constructor
HttpRuntime • What’s not there • CGI support • MIME types support • No ASP support • Nothing configured from IIS metabase • What is there • Everything specified in web.config • Full .NET environment (GAC, etc)
Warning • Created host limitations • Host assembly must be in either: • GAC • “bin” subdirectory of current directory • HttpRuntime hard-configures this • No documented way to change this
Motivation • So what? Why do I care? • Cassini’s not “production-quality” • Intended as lightweight server for Saturn • IIS 5, 6, 7 full-featured, HTTP cracking in kernel • Why not use that?
Motivation • Why you should care • IIS not appropriate in all situations • .NET more portable than COM (Rotor, Mono, Portable.NET, etc) • Lightweight front for WebServices • Lightweight server for debugging • Spelunking