提供 PDF 时出现 XML 解析错误
我正在尝试使用 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文件?
I'm trying to serve a pdf file from a database in ASP.NET using an Http Handler, but every time I go to the page I get an error
XML Parsing Error: no element found
Location: https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3
Line Number 1, Column 1:
Here is my HttpHandler code:
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;
}
}
}
Is there anything else I need to do (server configuration/whatever) to get my pdf file to load?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询字符串看起来不正确:
?noteId=1,msdsId=3
应该是noteId=1&msdsId=3
。我不知道这是否与 XML 错误有关,但这是第一个让我觉得错误的事情。The query string does not look right:
Surely
?noteId=1,msdsId=3
should benoteId=1&msdsId=3
. I don't know if this is related to the XML error, but it is the first thing that strikes me as wrong.