How to response from custom HttpHandler with "204 No Content"?

  • Thread starter Thread starter Alexander Smirnov
  • Start date Start date
A

Alexander Smirnov

I'm developing asp.net 2 web application and need to make a custom
http handler which sometime must send response with "204 No Content"
code.
I set HttpResponse.Status="204 No Content"; But asp automatically adds
headers such as "Content-Length: 0".
This causes an error on the client. HttpResponse.ClearHeaders()
doesn't help. How to make asp not to add headers (especially Content-
Length)?

Thanks in advance.
 
I'm developing asp.net 2 web application and need to make a custom
http handler which sometime must send response with "204 No Content"
code.
I set HttpResponse.Status="204 No Content"; But asp automatically adds
headers such as "Content-Length: 0".
This causes an error on the client. HttpResponse.ClearHeaders()
doesn't help. How to make asp not to add headers (especially Content-
Length)?

Thanks in advance.

Try the following:

Response.StatusCode = 204;
Response.Flush();
Response.SuppressContent = true;
 
Try the following:

Response.StatusCode = 204;
Response.Flush();
Response.SuppressContent = true;

Thanks! Now it doesn't send "Content-Length" header and no error
occurs on the client.
But there's another problem - it sends "Connection: close" even if I
do Response.AppendHeader("Connection","Keep-Alive"). And also it sends
some over headers. How to fully control headers in a custom http
handler (descendant of IHttpHandler)? In fact I don't wont any headers
to be sent, only the status line "HTTP/1.1 204 No Content\r\n\r\n" and
not to close the connection.
 
Thanks! Now it doesn't send "Content-Length" header and no error
occurs on the client.
But there's another problem - it sends "Connection: close" even if I
do Response.AppendHeader("Connection","Keep-Alive"). And also it sends
some over headers. How to fully control headers in a custom http
handler (descendant of IHttpHandler)? In fact I don't wont any headers
to be sent, only the status line "HTTP/1.1 204 No Content\r\n\r\n" and
not to close the connection.- Hide quoted text -

- Show quoted text -

Probably you have to rewrite it from the base class.

What is the problem exactly, why don't you like the "Connection:
close" in the response?
 
Back
Top