Question

I was using Response.Header.Add() before I notice that my code might run on server set in classic mode. In such a case, the exception "This operation requires IIS integrated pipeline mode." is raised.

I switched to Response.AddHeader() to solve my issue. This function seems older, but it isn't deprecated. I would like to know, do you see any reason for using Response.Header.Add() over Response.AddHeader()? Could you please explain ?

Was it helpful?

Solution

Response.AddHeader() is an older method, geared towards IIS6. Response.AddHeader provides you with a basic way to add custom headers to the Response Headers collection, but doesn't really provide you with a means to otherwise manipulate the collection (like, you can't remove a header from the collection - though you can clear them all with Response.ClearHeaders()). Response.Header.Add() is newer and requires Integrated Pipeline Mode to function, which is only supported in IIS7 and later...

"The Headers property is only supported with the IIS 7.0 integrated pipeline mode and at least the .NET Framework 3.0. When you try to access the Headers property and either of these two conditions is not met, a PlatformNotSupportedException is thrown." -Linky

It's my understanding that IIS6 uses ASAPI to invoke .Net, effectively limiting how things like response headers can be worked with. With IIS7 Integrated mode, a "unified request-processing pipeline that combines the ASP.NET request pipeline with the IIS core request pipeline", providing greater flexibility in working within the request/response life cycle...

Here are a couple of links that may help illuminate the subject for you - Moving an ASP.Net Application from IIS 6.0 to IIS 7.0 and HTTP Request Lifecycle Events in IIS Pipeline that every ASP.NET Developer Should Know.

I hope that this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top