title: Unable to download the PDF file from URL
body: <p>I need to download an .PDF file from a website : https://XXXXX/XXXX/XXXXXXX.pdf when user click's on link button. Below code is working fine in local but when I try to click on link button for downloading the file after deploying into server, First time it is working fire but next consecutive downloads, It is displaying as The XXXX.PDF download was interrupted or file cannot be downloaded.</p>
  <p>try
  {</p>
  <pre><code>         string fullFileName =string.Empty;
              LinkButton btn = (LinkButton)(sender);
              string filepath = btn.CommandArgument;
              string fileName = btn.Text; 
  
          if (fileName != null &amp;&amp; !string.IsNullOrEmpty(fileName))
          {
                             
              fullFileName = filePath +fileName ;
  
              int bytesToRead = 10000;
  
              // Buffer to read bytes in chunk size specified above
              byte[] buffer = new Byte[bytesToRead];
  
              //string fileName = System.IO.Path.GetFileName(fullFileName);
              //Create a WebRequest to get the file
              System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | (SecurityProtocolType)768/*TLS1.1*/ | (SecurityProtocolType)3072/*TLS1.2*/;
              HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(fullFileName);
              
  
              //Create a response for this request
              HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
  
              if (fileReq.ContentLength &gt; 0)
                  fileResp.ContentLength = fileReq.ContentLength;
  
              //Get the Stream returned from the response
              stream = fileResp.GetResponseStream();
  
              // prepare the response to the client. resp is the client Response
              var resp = HttpContext.Current.Response;
  
              //Indicate the type of data being sent
              resp.ContentType = &quot;application/PDF&quot;;
  
              //Name the file 
              resp.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=\&quot;&quot; + fileName + &quot;\&quot;&quot;);
              resp.AddHeader(&quot;Content-Length&quot;, fileResp.ContentLength.ToString());
  
              int length;
              do
              {
                  // Verify that the client is connected.
                  if (resp.IsClientConnected)
                  {
                      // Read data into the buffer.
                      length = stream.Read(buffer, 0, bytesToRead);
  
                      // and write it out to the response's output stream
                      resp.OutputStream.Write(buffer, 0, length);
  
                      // Flush the data
                      resp.Flush();
  
                      //Clear the buffer
                      buffer = new Byte[bytesToRead];
                  }
                  else
                  {
                      // cancel the download if client has disconnected
                      length = -1;
                  }
              } while (length &gt; 0); //Repeat until no data is read
          }
          else
          {
              lblFile.Text = &quot;File Name is missing&quot;;
              lblFile.Visible = true;
          }
       }
         
      catch (Exception ex)
      {
          
      }
      finally
      {
  
          if (stream != null)
          {
              //Close the input stream
              stream.Close();
          }
      }
  </code></pre>
  <p>Can someone please guide me why it is failing in server</p>