469,889 Members | 1,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

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

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.

Mar 21 '07 #1
3 6635
On Mar 21, 6:33 pm, "Alexander Smirnov" <s_alexande...@list.ruwrote:
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;

Mar 21 '07 #2
On Mar 22, 12:56 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
On Mar 21, 6:33 pm, "Alexander Smirnov" <s_alexande...@list.ruwrote:
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;
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.

Mar 22 '07 #3
On Mar 22, 8:24 am, "Alexander Smirnov" <s_alexande...@list.ruwrote:
On Mar 22, 12:56 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:


On Mar 21, 6:33 pm, "Alexander Smirnov" <s_alexande...@list.ruwrote:
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;

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?

Mar 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Michael Strorm | last post: by
12 posts views Thread by Jean-Marc Blaise | last post: by
11 posts views Thread by Trapulo | last post: by
1 post views Thread by dave8421 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.