Tue, 13 Nov 2007 22:05:36 GMT
Carlos Aguilar Mares
Senior Development Lead
It seems the architecture of IIS has changed substantially with this release. If IIS6 was the bedrock that got us to Application Pools, and good .NET integration, IIS7 takes us to a new level. The IIS team has done a lot of refactoring to get there.
IIS6 |
IIS7 |
Monolithic server implementation |
Componentised Server |
Limited customisation |
Pluggable modular functionality |
Fixed functionality |
Small generic request pipeline |
Extensibility limited to ISAPI Filters |
Enables lightweight servers and specialised servers |
In IIS6, ASP.NET is implemented as an ISAPI filter, which sits right at the end of the pipeline. This caused a few problems – including duplication of features and wasted computation; authentication in ASP.NET would happen after IIS6 authenticated anyway. Another example of authentication badness in IIS6 occurs when you try to secure non-ASP.NET assets: you can only accomplish this by funnelling all HTTP requests via ASP.NET.
IIS7 offers two integrations models: Classic Mode (for compatibility – like IIS6) and Integrated Mode. ASP.NET is now implemented as a bundle of modules that fit into the redesigned IIS pipeline. Integrated Mode can process *all* requests and gives hider fidelity notifications.
.NET Extensibility
- Existing ASP.NET API – using IHttpModel and IHttpHandler types
- Expanded ASP.NET APIs
- New HttpApplication Events
- MapRequestHandler, LogRequest, PostLogRequest
- Inject and modify IIS system headers and collections
- HttpRequest.Headers
- HttpReponse.Headers
- HttpReponse.DisableKernelCache
- HttpReponse.ServerVariables
- New HttpApplication Events
Handlers vs Modules
Modules |
Handlers |
Provide services to all requests |
Provides services to specific extensions |
Basic Authentication module |
Handlers ISAPI handler (.dll) |
Compression module (etc) |
Static handler (.htm, .jpg, .gif, etc) |
IIS 7 pipeline allows native and managed modules and handlers
- “Integrated” Application Pool mode
- use the managed modules and handlers
- ASP.NET v2.0 and above can be configured to run in Integrated Mode
- “Classic” Application Pool
- IIS 6 style invocation of .NET
- ASP.NET v1.1 and earlier can only be configured to run in Classic Mode
Building Managed Modules and Handlers
Modules – Building a Module to cause IIS to Log to SQL Server
The steps to build a module are more or less:
- Add a class to your project – e.g. public class SqlLogModule: IHttpModule
-
Edit the code!
-
Add to public void Init()
context.LodgRequest += new EventHandler(OnLogRequest) -
Fill in OnLogRequest
HttpApplication app = (HttpApplication) sender;
Log(app.Context); // TODO: write this function! :)
-
-
IIS Manager -> Configure Modules -> Managed Modules
-
Add Managed Module
- Name "SqlLogModule"
- Type "SqlLogModule"
This adds web.config to our project!
-
- Edit web.config <system.webServer> section. ASP.NET ignores this section; it’s only read by IIS7.
[Side question: how is all this possible? Won’t ASP.NET 2.0 keel over at this point? Answer: no, .NET v2.0 was refactored for Vista and Server 2008.]