English 中文(简体)
Mono / Lighttpd - Garbage text added to SVG file returned via Response.Write()
原标题:

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.

最佳回答

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.

问题回答

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签