Iis 7 从IIS6到IIS7的MemoryStream下载失败

Iis 7 从IIS6到IIS7的MemoryStream下载失败,iis-7,iis-6,download,memorystream,Iis 7,Iis 6,Download,Memorystream,我们正在从IIS6转换到IIS7,除了下载部分,一切都进行得很顺利。发生的情况是下载已启动,但似乎发生了重定向,用户下载了我们的default.aspx页面,而不是请求的文件。下面是我们与IIS6一起使用的代码 Private Sub GetFile(ByVal ReportQueueId As System.Int32, _ ByVal FileName As System.String _ ) Dim s

我们正在从IIS6转换到IIS7,除了下载部分,一切都进行得很顺利。发生的情况是下载已启动,但似乎发生了重定向,用户下载了我们的default.aspx页面,而不是请求的文件。下面是我们与IIS6一起使用的代码

Private Sub GetFile(ByVal ReportQueueId As System.Int32, _
                    ByVal FileName As System.String _
                    )
    Dim stream As System.IO.MemoryStream = Nothing
    Dim lngRecordCount As System.Int32 = 0
    Dim objWebClient As New System.Net.WebClient
    Dim strServerName As System.String

    Try
        strServerName = Page.Request.Item("SERVER_NAME").ToString()

        Dim fURI As New System.Uri("http://" & strServerName & "/reportmonitor/" & FileName)
        ' Open the file into a stream. 
        stream = New System.IO.MemoryStream(objWebClient.DownloadData(fURI), False)

        ' Total bytes to read: 
        Dim bytesToRead As Long = stream.Length

        Page.Response.Clear()
        Page.Response.ContentType = "application/octet-stream"
        Page.Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName.ToString())
        Page.Response.AddHeader("Content-Length", bytesToRead.ToString())


        ' Read the bytes from the stream in small portions. 
        While bytesToRead > 0
            ' Make sure the client is still connected. 
            If Response.IsClientConnected Then
                ' Read the data into the buffer and write into the output stream. 
                Dim buffer As Byte() = New Byte(9999) {}
                Dim length As Integer = stream.Read(buffer, 0, 10000)
                Response.OutputStream.Write(buffer, 0, length)
                Response.Flush()

                ' We have already read some bytes.. need to read 
                ' only the remaining. 
                bytesToRead = bytesToRead - length
            Else
                ' Get out of the loop, if user is not connected anymore.. 
                bytesToRead = -1
            End If
        End While

        'Update status
        lngRecordCount = UpdateStatus(ReportQueueId, _
                                      listcounts_common.ListCountsCommon_CL.ReportQueueStatus.rqsDownloaded _
                                      )
    Catch SystemException As System.Exception
        'Update status
        lngRecordCount = UpdateStatus(ReportQueueId, _
                                      listcounts_common.ListCountsCommon_CL.ReportQueueStatus.rqsOnHold _
                                      )

        'most likely a 404 file not found error
        Me.lblErrorMessage.Text = CLASS_NAME & ":GetFile: " & SystemException.Message.ToString
        Me.lblErrorMessage.Visible = True
    Finally
        objWebClient = Nothing
        stream = Nothing
    End Try
End Sub
运行此代码后,我读到的唯一其他内容可能是调用GetFile()的父函数,我们有以下代码:

' stops page html output. If this is not done, un-desired html code will be added to csv files
 Page.Response.End()
关于IIS6和II7之间的区别以及这个过程有什么想法吗?我尝试过的一切都没有奏效。新站点正在以Itegrated模式运行.NET 4

谢谢你

更新

我将fURI修改为外部文件:

fURI = New System.Uri("http://manuals.info.apple.com/en_US/ipad_user_guide.pdf")

这个文件下载得很好,所以我假设这是IIS7中的权限问题……关于我可能遗漏的内容有什么想法吗?

由于该网站正在使用表单身份验证,因此在web.config中为虚拟服务器添加允许的位置路径解决了转换为IIS7的问题

<location path="reportmonitor">
<system.web>
  <authorization>
    <allow users="*" />
  </authorization>
</system.web>
</location>