我正在尝试使用Http Handler从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文件吗?
答案 0 :(得分:2)
查询字符串看起来不正确:
https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3
当然?noteId=1,msdsId=3
应为noteId=1&msdsId=3
。我不知道这是否与XML错误有关,但这是第一件让我感到错误的事。