Public Class fichero
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Persona") Is Nothing Then
            Response.Redirect("default.aspx")
        End If
        Dim idAsis = Request.QueryString("id")
        Dim nif = Session("usuario")
        Dim tabla = Request.QueryString("t")
        Dim cl = Request.QueryString("cl")
        Dim sCl = tsl5.crypt.SHA1("M3Soft." & idAsis.ToString)
        If sCl <> cl Then
            Session.Add("mensajeerror", "Trámite no válido")
            Response.Redirect("/MensajesError.aspx", False)
        Else

            Dim url3 As String = ConfigurationManager.AppSettings("RutaRes").ToString + "/api/ObtenFicheroAtransmitir?idRegistro=" + idAsis + "&Tabla=" + tabla + "&nif=" + nif
            Dim clienteHTTP3 As New Net.WebClient()
            clienteHTTP3.Encoding = System.Text.Encoding.UTF8
            Dim respuesta3 As String = clienteHTTP3.DownloadString(url3)
            Dim deserializador3 As New System.Web.Script.Serialization.JavaScriptSerializer()
            deserializador3.MaxJsonLength = Integer.MaxValue
            Dim datos As Newtonsoft.Json.Linq.JObject =
           Newtonsoft.Json.JsonConvert.DeserializeObject(Of Newtonsoft.Json.Linq.JObject)(respuesta3)
            Dim fichero As Byte() = datos.Item("pdf")

            Response.AddHeader("content-disposition", "inline;filename=""" + idAsis + ".pdf""")
            'Response.AddHeader("Cache-Control", "max-age=2592000")
            If fichero IsNot Nothing Then
                Response.ContentType = "application/pdf"
                Response.BinaryWrite(fichero)
                Response.Flush()
                Response.End()
            End If
        End If


    End Sub
End Class