Ошибка загрузки MemoryStream с IIS6 на IIS7

Мы переходим с 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 и 7 и этим процессом? Все, что я пробовал, не сработало. Новый сайт работает в интегрированном режиме .NET 4.

Спасибо...

ОБНОВЛЕНИЕ

Я изменил fURI на внешний файл:

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

Этот файл загружается отлично, поэтому я предполагаю, что это проблема с разрешениями в IIS7 ... есть идеи о том, что я, возможно, пропустил?


person KeyOfJ    schedule 11.04.2013    source источник


Ответы (1)


Поскольку сайт использует проверку подлинности с помощью форм, добавление допустимого пути к местоположению в web.config для виртуального устройства решило проблемы при преобразовании в IIS7.

<location path="reportmonitor">
<system.web>
  <authorization>
    <allow users="*" />
  </authorization>
</system.web>
</location>
person KeyOfJ    schedule 15.04.2013