Mono / Lighttpd - 添加到通过 Response.Write() 返回的 SVG 文件中的垃圾文本

发布于 2024-08-11 19:22:10 字数 1453 浏览 3 评论 0原文

我正在开发一个管理植物群的网络应用程序。该应用程序的一个功能是能够以图表形式查看植物之间的关系。该可视化结果生成为点文件,然后使用 GraphViz 将其转换为 SVG。然后,使用 Response.Write() 技术,将生成的 SVG 标记通过 .aspx 文件呈现到浏览器。

Aspx 标记:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Visualisation.aspx.cs" Inherits="Webapp.PopulationManager.Visualisation" %>

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            // ...snip...
            string svgString = PopulationModule.VisualiseTable(connectionTable, title, url.ToString());

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "image/svg-xml";
            Response.AddHeader("Content-Disposition", string.Format("inline;filename={0}", filename));
            Response.Write(svgString);
            Response.Flush();
        }
    }

此技术在我的 Windows 开发计算机上完美运行(弹出一个对话框,要求我保存/打开 SVG 文件)。

但是,当部署到托管此应用程序的 Linux 服务器时,它会失败 - 页面返回 SVG 标记,但将大约 5-6 个字符的垃圾字符串添加为第一行,导致浏览器无法解析 SVG 文件。

Linux 主机运行 RHEL5、Mono 1.9 和 Lighttpd(使用 fast-cgi 与 Mono 对话)。

我已经验证 SVG 标记是在 Linux 服务器上干净地生成的;如果我使用 XSP2 而不是 Lighttpd 运行 Web 应用程序,该页面将按预期工作。垃圾行是在生成 SVG 标记后添加到某处的(因此我不能在写出响应之前简单地删除第一行)。

有谁知道可能是什么原因造成的?选项、想法和想法深受好评!

谢谢。

编辑:

字符根据我为其创建可视化的实体而有所不同 - 但对于给定实体保持相同。因此,如果我为对象 A 创建 SVG 可视化,我总是会在第一行将字符串 1f35 作为垃圾。

I am developing a web application that manages a population of plants. One feature of the application is the ability to view relationships between plants as a graph. This visualisation is generated as a dot file, then turned into SVG using GraphViz. The resulting SVG markup is then rendered to the browser via an .aspx file, using the Response.Write() technique.

Aspx markup:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Visualisation.aspx.cs" Inherits="Webapp.PopulationManager.Visualisation" %>

Codebehind:

protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            // ...snip...
            string svgString = PopulationModule.VisualiseTable(connectionTable, title, url.ToString());

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "image/svg-xml";
            Response.AddHeader("Content-Disposition", string.Format("inline;filename={0}", filename));
            Response.Write(svgString);
            Response.Flush();
        }
    }

This techniques works perfectly on my Windows development machine (a dialog pops up asking me to save/open the SVG file).

However it fails when deployed to the Linux server that is hosting this app - the page returns the SVG markup, but a garbage string of about 5-6 characters is added as the first line, causing the browser to fail parsing the SVG file.

The Linux host runs RHEL5, Mono 1.9, and Lighttpd (with fast-cgi to talk to Mono).

I have verified that the SVG markup is generated cleanly on the Linux server; and if I run the web app with XSP2 instead of Lighttpd, the page works as expected. The garbage line is added somewhere after the SVG markup is generated (so I can't simply remove the first line before writing out the response).

Does anyone know what might be causing this? Options, ideas, and thoughts greatly recieved!

Thanks.

EDIT:

The characters vary depending on the entity I create a visualisation for - but remain the same for a given entity. So if I create an SVG visualtion for object A, I'll always get the string 1f35 as garbage in the first line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

亢潮 2024-08-18 19:22:10

您的内容类型无效,应为“image/svg+xml”。

Your Content-Type is invalid, should be "image/svg+xml".

谜兔 2024-08-18 19:22:10

请更新到最新的 Mono (2.4.2.3),然后重试。由于 IIRC Red Hat 没有适用于 Mono 的 rpm,因此您必须构建它并从源代码安装。 1.9 已经过时了。从那时起,Mono 的所有部分都得到了改进。

Please update to a recent Mono (2.4.2.3) and then try again. As IIRC Red Hat does not have rpms for Mono, you will have to build it and install from source. 1.9 is terribly outdated. All parts of Mono have been improved since then.

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