1

I have created an application in VB.NET that is responsible for creating a PDF using iTextSharp. It is hosted on a Windows Web Server with IIS. But sometimes it happens that the version delivered by the server is an old one, it does not show the latest changes made to the structure of the PDF. To solve it, I must upload the version that I have on my PC back to the server. Although I have not made any changes to the source code and it is exactly the same as the one on the server. Every time I invoke the .aspx file I do it with a random value parameter to try to avoid the cache, but apparently it is not the solution. I also have the following statement in the code: Response.Cache.SetCacheability (HttpCacheability.NoCache) Thank you very much for any help you can give me.
Here is how I create PDF: I use a function to create PDF and return it into a MemoryStream :


SendOutPDF(CreatePDF("Title", nro), nro)  
 
Public Function CreatePDF(ByVal Titulo As String, ByVal Numero As Integer) As System.IO.MemoryStream  
    Dim PDFData As MemoryStream = New MemoryStream  
    ... 
    Dim pdfDoc As iTextSharp.text.Document  
    ...  
    Dim pdfWrite As PdfWriter = 
    iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, PDFData)  
    ... 
    Return PDFData  
End Function  
Protected Sub SendOutPDF(ByVal PDFData As System.IO.MemoryStream, ByVal num As Integer)  
    Response.Clear()  
    Response.ClearContent()  
    Response.ClearHeaders()  
    Response.ContentType = "application/pdf"  
    Response.Charset = String.Empty  
    Response.AddHeader("content-disposition", "attachment;filename=" & num & ".pdf")  
    Response.Cache.SetCacheability(HttpCacheability.NoCache)  
    Response.OutputStream.Write(PDFData.GetBuffer, 0, PDFData.GetBuffer.Length)  
    Response.OutputStream.Flush()  
    Response.OutputStream.Close()  
    Response.End()  
End Sub
  • How does the app create the PDF? If it saves it to the disk drive before delivering it, can you check the version on the disk drive independently of the download? – Andrew Morton Dec 29 '21 at 20:40
  • @AndrewMorton, I use a function that creates PDF into a MemoryStream and then send it to a function : `Response.Clear() Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.Charset = String.Empty Response.AddHeader("content-disposition", "attachment;filename=" & nParam1 & ".pdf") Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.OutputStream.Write(PDFData.GetBuffer, 0, PDFData.GetBuffer.Length) Response.OutputStream.Flush() Response.OutputStream.Close() Response.End()` – user2524191 Dec 31 '21 at 09:46
  • You wrote "To solve it, I must upload the version that I have on my PC back to the server." - do you mean that you upload a PDF to the server? If so, does the server modify the PDF before sending it to the user? – Andrew Morton Dec 31 '21 at 10:33
  • @AndrewMorton, I have to upload the .aspx file (the one that generates de PDF). No PDF files are saved in the process – user2524191 Dec 31 '21 at 18:02
  • It would be better to have the code which returns the data in an .ashx handler. I'm not sure, but I suspect that the *server* might be caching the response and that page is removed from the cache when you re-upload it - in an .ashx handler you can specify that it is not reusable and so be sure that a new file will be sent every time. [When is a Generic HttpHandler (an ashx, the IHttpHandler interface) reusable?](https://stackoverflow.com/q/10806214/1115360) leads to plenty of information on the subject. – Andrew Morton Dec 31 '21 at 18:09

0 Answers0