我正在尝试使用 Http 处理程序从 ASP.NET 中的数据库中提供 pdf 文件,但每次我转到该页面时都会出现错误
XML Parsing Error: no element found
Location: https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3
Line Number 1, Column 1:
这是我的 HttpHandler 代码:
public class NoteFileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString.HasKeys())
{
if (context.Request.QueryString["noteId"] != null && context.Request.QueryString["msdsId"] != null)
{
string nId = context.Request.QueryString["noteId"];
string mId = context.Request.QueryString["msdsId"];
DataTable noteFileDt = App_Models.Notes.GetNoteFile(nId, mId);
if (noteFileDt.Rows.Count > 0)
{
try
{
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=" +
noteFileDt.Rows[0][0] + ".pdf");
context.Response.ContentType = "application/pdf";
byte[] file = (byte[])noteFileDt.Rows[0][1];
context.Response.BinaryWrite(file);
context.Response.End();
}
catch
{
context.Response.ContentType = "text/plain";
context.Response.Write("File Not Found");
context.Response.StatusCode = 404;
}
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
我还需要做什么(服务器配置/其他)来加载我的 pdf 文件吗?