如何在安全的虚拟主机上显示的网页中显示pdf文件

时间:2014-05-25 05:41:04

标签: asp.net pdf

我正在尝试使用FTP在aspx页面中显示pdf文件,但总是错误'找不到文件' 这是我的代码..

Dim localFile As String = Server.MapPath("~/Test.pdf")
Dim URI As String = "ftp://mysitename/%2f/httpdocs/Folder1/Folder2/Folder3/image123.pdf"
Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)

ftp.Credentials = New NetworkCredential("username", "password")
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0

                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0

                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using

            Response.Redirect("~/Test.pdf")

此代码从VS2012完美运行,因为在.sln文件所在的位置创建了Test.pdf文件。但是当在网络托管中上传时,它会显示错误:

远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。  我也试过..

Dim localFile As String = HttpContext.Current.Server.MapPath("~/Test.pdf")
Dim localfile As String = HostingEnvironment.MapPath("~/Test.pdf") 

但是一切都在静脉.. 请帮忙。感谢..

0 个答案:

没有答案