Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is AppendHeader exactly the same as AddHeader?

Tags:

asp.net

We use ASP.Net 4.0. In our code we regularly use Response.AddHeader("x", "y"). Is this exactly the same as Response.AppendHeader("x", "y")? I read that AppendHeader only exists for compatibility with classic ASP, which we do not use.

Can we, without any concerns, replace AddHeader with AppendHeader?

like image 702
RandomProgrammer Avatar asked Apr 13 '11 11:04

RandomProgrammer


2 Answers

They are the same, so yes, you can replace HttpResponse.AddHeader with HttpResponse.AppendHeader.

From MSDN

AddHeader is the same as AppendHeader and is provided only for compatibility with earlier versions of ASP. With ASP.NET, use AppendHeader.

A quick peek with Reflector confirms that HttpResponse.AddHeader just calls HttpResponse.AppendHeader.

like image 57
Rob Levine Avatar answered Sep 20 '22 19:09

Rob Levine


They are not the same (at least for HttpListenerContext).

Here is the test:

ctx.Response.AddHeader("a", "b"); ctx.Response.AddHeader("a", "c"); 

The result is:

HTTP/1.1 200 Server: Microsoft-HTTPAPI/2.0 a: c Date: Mon, 12 Nov 2012 16:42:01 GMT 

And now like this:

ctx.Response.AddHeader("a", "b"); ctx.Response.AppendHeader("a", "c"); 

The result is:

HTTP/1.1 200 Server: Microsoft-HTTPAPI/2.0 a: b a: c Date: Mon, 12 Nov 2012 16:53:29 GMT 
like image 28
Pawel Cioch Avatar answered Sep 18 '22 19:09

Pawel Cioch