1

Is there any way to add custom headers without creating HttpHandler? I've tried the following two APIs but the former is throwing error and the latter is working fine but when the page is either redirected or posted to another page. The header is lost. Thanks for your suggestion.

    Response.Headers.Add()
    Response.AppendHeader()

Environment: ASP.NET 3.5 & IIS 6

2
  • Why don't you add it to the IIS server itself if you need it in every page (well i'm assuming) - Check this link Commented Nov 22, 2011 at 8:42
  • @DidierG ... The header information is only available at runtime so I am not able to add it in IIS server. Commented Nov 22, 2011 at 8:59

1 Answer 1

2

According to MSDN documentation:

"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."

Since you are using IIS6 I'd expect you to get a PlatformNotSupportedException exception raised. Are you?

Try using Response.AppendHeader() method instead. For example:

Response.AppendHeader("CustomAspNetHeader", "Value1");

You can also use Response.ClearHeaders() to remove any headers first, if need be.

Sign up to request clarification or add additional context in comments.

2 Comments

In fact, I am also using Response.AppendHeader() method but when the page is cross-posted or redirected to another page, the header is lost.
I'd recommend using fiddler2.com/fiddler2 to view the headers being sent to try and ascertain what is going on, then...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.