提供 PDF 时出现 XML 解析错误

发布于 2024-08-28 08:27:37 字数 1864 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装爱人 2024-09-04 08:27:37

查询字符串看起来不正确:

https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3

?noteId=1,msdsId=3 应该是 noteId=1&msdsId=3。我不知道这是否与 XML 错误有关,但这是第一个让我觉得错误的事情。

The query string does not look right:

https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3

Surely ?noteId=1,msdsId=3 should be noteId=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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文