Why are we using Response.ClearHeaders ()?

I copied a snippet of code to send files to the browser. I do not know why we use the lines below, so deleting them does not affect my development environment.

Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; 

Can anyone provide a simple breakthrough in purpose and relevance.

thanks

+6
source share
2 answers

Response.Clear ();

If you have already written something to the buffer, you need to clear it so that extraneous content is not included.

Response.ClearHeaders ();

If the content type was previously specified, for example, you probably don't want this. Any number of HTTP headers may already be set, another good example is cache management.

Response.Buffer = false;

It makes no sense to buffer the output, if you are ready to upload the file, just send it and do not lose memory.

+10
source

Response.ClearHeaders make sure no headers are sent to the client. This is necessary because before this function or event, the page could send some headers, for example, content type or cache control. You need Response.Clear because the page could display some html in the buffer.

+2
source

Source: https://habr.com/ru/post/892105/


All Articles