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?
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With