流式PDF适用于Localhost,但不适用于已发布的网站

时间:2014-08-13 18:35:24

标签: asp.net vb.net visual-studio-2010 pdf intranet

我目前正在尝试在我公司网络上的网站上打开PDF文件。我以前有这个工作,但现在由于某种原因它不起作用。这就是我所拥有的:

我正在使用模拟来访问该文件。它具有域管理员权限。这是来自我的web.config文件(用户名/密码被更改):

<identity impersonate="true" password="pass" userName="domain\user" />

我使用此代码在窗口中打开PDF:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
        Dim strPath As String = CStr(Session("DWGPath"))
        strPath = "file://san01/prodeng/" + Mid(strPath, 4)
        strPath = Replace(strPath, "\", "/")

        Dim pdfPath As String = strPath
        Dim client As WebClient = New WebClient()
        Dim buffer As Byte() = client.DownloadData(pdfPath)
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-length", buffer.Length.ToString())
        Response.BinaryWrite(buffer)
        Response.End()
    Catch exa As WebException
        Response.Redirect("DrawingError.aspx")
    Catch ex As Exception
        Throw ex
    End Try
End Sub

这不起作用。它将我重定向到“DrawingError.aspx”页面。此链接显示“Session(”DWGPath“)”变量。我可以把这个变量粘贴到我的浏览器中,PDF打开没有问题。

但是,如果我改变我的代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
        Dim strPath As String = CStr(Session("DWGPath"))

        Dim pdfPath As String = strPath
        Dim client As WebClient = New WebClient()
        Dim buffer As Byte() = client.DownloadData(pdfPath)
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-length", buffer.Length.ToString())
        Response.BinaryWrite(buffer)
        Response.End()
    Catch exa As WebException
        Response.Redirect("DrawingError.aspx")
    Catch ex As Exception
        Throw ex
    End Try
End Sub

它仍然不起作用。

该帐户还具有对包含PDF的文件夹的完全控制权限。

任何帮助或见解将不胜感激。谢谢!

编辑:如果我抛出exa然后我得到这个:

The account used is a computer account. Use your global user account or local user account to access this server.

1 个答案:

答案 0 :(得分:2)

我假设您正在运行IIS。转到此应用的应用程序池,并将其运行的标识更改为domain\user帐户。看看是否能解决您的问题。

您希望确保此帐户的密码不会更改,否则密码过期时密码将失败。