Programmatically (not declaratively) Configuring the Request Pipeline in IIS 7

Programmatically (not declaratively) Configuring the Request Pipeline in IIS 7

am 18.04.2008 18:13:36 von Peter Schwartz

In IIS5.1 and 6, if I wanted to customize the request pipeline for an
ASP.NET application, I would run some logic during Application_Start that
wired up various event handling methods to the various pipeline events.

But things are different with IIS 7. In IIS 7, the ASP.NET request
processing pipeline overlays the IIS pipeline directly, essentially
providing a wrapper over it instead of plugging into it (as was the case
with IIS 5.1 and 6).

My question: How can I *programmatically* wire up ASP.NET event handling
methods to handle the various pipeline events (of this new "combined"
request pipeline)? Please note that I am perfectly clear on how to
*declaratively* configure the pipeline (via .config files).

My situation is that I must hit a database to determine how to configure the
request pipeline - specifically to hook up a custom authentication module as
well as another module that does some "non standard" processing whenever an
ASP.NET Web application first starts (e.g., upon the first, and only the
first, request after it's app pool is recycled). In the "old world" I would
do this activity during Application_Start of the ASP.NET application. I
don't know what the equivalent would be in the "new world" of IIS7.

Thanks.

Re: Programmatically (not declaratively) Configuring the Request

am 21.04.2008 21:13:15 von David Wang

On Apr 18, 9:13=A0am, "Jordan S." wrote:
> In IIS5.1 and 6, if I wanted to customize the request pipeline for an
> ASP.NET application, I would run some logic during Application_Start that
> wired up various event handling methods to the various pipeline events.
>
> But things are different with IIS 7. In IIS 7, the ASP.NET request
> processing pipeline overlays the IIS pipeline directly, essentially
> providing a wrapper over it instead of plugging into it (as was the case
> with IIS 5.1 and 6).
>
> My question: How can I *programmatically* wire up ASP.NET event handling
> methods to handle the various pipeline events (of this new "combined"
> request pipeline)? Please note that I am perfectly clear on how to
> *declaratively* configure the pipeline (via .config files).
>
> My situation is that I must hit a database to determine how to configure t=
he
> request pipeline - specifically to hook up a custom authentication module =
as
> well as another module that does some "non standard" processing whenever a=
n
> ASP.NET Web application first starts (e.g., upon the first, and only the
> first, request after it's app pool is recycled). In the "old world" I woul=
d
> do this activity during Application_Start of the ASP.NET application. I
> don't know what the equivalent would be in the "new world" of IIS7.
>
> Thanks.


You can programmatically wire which events a module will subscribe on
a given request, in both native and managed code. You cannot
programmatically add/remove modules on a given request, on the fly.

And for the "non standard" processing -- it sounds like you have a
singleton init design pattern, which is really not tied to
"Application_Start".

Regarding event timing -- it is not a good idea to expect certain
ordering or frequency of events between IIS7 managed module and
ASP.Net HttpModule -- those are some of the very things that we
changed (out of necessity) in integrating the event pipelines
together.

I don't see why you cannot use BeginRequest to accomplish what you
need.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//