У меня проблема с моим обработчиком ASHX, который генерирует PDF.
Когда пользователь нажимает кнопку «Просмотр PDF», он ищет файл PDF в базе данных и отображает его, но еслитам нет файла PDF, там должна отображаться пустая страница с надписью «PDF недоступен», но вместо этого я получаю ошибку «пустая ссылка» в этой строке кода:
ms.WriteTo(context.Response.OutputStream)
Ниже приведен коддля обработчика:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'This class takes the uniqueidentifier of an image stored in the SQL DB and sends it to the output stream
'This saves storing copies of image files on the web server as well as in the DB
context.Response.Clear()
If context.Request.QueryString("fileSurveyID") IsNot Nothing Then
Dim filesID As String = context.Request.QueryString("fileSurveyID")
Dim fileName = String.Empty
Dim ms As MemoryStream = GetPDFFile(filesID)
context.Response.ContentType = "application/pdf"
context.Response.AddHeader("Content-Disposition", "attachment;filename=" & fileName)
context.Response.Buffer = True
ms.WriteTo(context.Response.OutputStream)
context.Response.End()
Else
context.Response.Write("<p>No pdf file</p>")
End If
End Sub
Может кто-нибудь сказать мне, как избавиться от этой ошибки?