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

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

Guest

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;
 
A

Alexander Smirnov

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

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top