System.Web.HttpResponse.Flush C# (CSharp) Method

Flush() private method

private Flush ( bool final_flush ) : void
final_flush bool
return void
		internal void Flush (bool final_flush)
		{
			if (completed)
				throw new HttpException ("Server cannot flush a completed response");
			
			DoFilter (final_flush);
			if (!headers_sent){
				if (final_flush || status_code != 200)
					use_chunked = false;
			}

			bool head = ((context != null) && (context.Request.HttpMethod == "HEAD"));
			if (suppress_content || head) {
				if (!headers_sent)
					WriteHeaders (true);
				output_stream.Clear ();
				if (WorkerRequest != null)
					output_stream.Flush (WorkerRequest, true); // ignore final_flush here.
				completed = true;
				return;
			}
			completed = final_flush;
			
			if (!headers_sent)
				WriteHeaders (final_flush);

			if (context != null) {
				HttpApplication app_instance = context.ApplicationInstance;
				if (app_instance != null)
					app_instance.TriggerPreSendRequestContent ();
			}

			if (IsCached)
				cached_response.SetData (output_stream.GetData ());

			if (WorkerRequest != null)
				output_stream.Flush (WorkerRequest, final_flush);
		}

Same methods

HttpResponse::Flush ( ) : void

Usage Example

Example #1
0
        public void GetImage(HttpResponse reponse, int id)
        {
            using (SqlConnection connection = new SqlConnection("Data Source=DESKTOP-5A9RHHB;Initial Catalog=EcommerceSimplifie; Integrated Security=True"))
            {
                //try
                //{
                SqlCommand command = new SqlCommand("select Picture.PictureBinary, Picture.MimeType from Picture inner join Product_Picture_Mapping on Picture.Id = Product_Picture_Mapping.PictureId where ProductId = @id and DisplayOrder = 1;");
                command.Connection = connection;
                command.Parameters.Add(new SqlParameter("@id", id));

                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {

                    //type de l'image
                    string typeMime = reader.GetString(1);
                    reponse.ContentType = (string.IsNullOrEmpty(typeMime)) ? "image/jpeg" : typeMime;

                    //mise en cache
                    reponse.Cache.SetCacheability(HttpCacheability.Public);

                    int indexDepart = 0;
                    int tailleBuffer = 1024;
                    long nombreOctets = 0;
                    Byte[] flux = new Byte[1024];

                    nombreOctets = reader.GetBytes(0, indexDepart, flux, 0, tailleBuffer);

                    while (nombreOctets == tailleBuffer)
                    {
                        reponse.BinaryWrite(flux);
                        reponse.Flush();
                        indexDepart += tailleBuffer;
                        nombreOctets = reader.GetBytes(0, indexDepart, flux, 0, tailleBuffer);
                    }
                    if (nombreOctets > 0)
                    {
                        reponse.BinaryWrite(flux);
                        reponse.Flush();
                    }
                    reponse.End();

                }
                //catch(Exception)
                //{
                //    throw new Exception("Pas d'image disponible.");
                //}
                //}
            }
        }
All Usage Examples Of System.Web.HttpResponse::Flush