views:

107

answers:

2

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.

A: 

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.

skolima
Thanks for the suggestion. I haven't been able to get a build of a more recent Mono version working. Also, the page serves up correctly under XSP2 - so I'm inclinded to believe it's something to do with lighttpd / fast-cgi setup? (Both of which I have little experience of!)
rob
You are probably right. However, I am pretty sure that the fast-cgi support in Mono also has been improved, that's why update was the first thing I suggested. For compiling mono, `./configure` should list any missing or outdated dependencies.
skolima
I'll give building a new version of mono another go - failing that, I'll see if the computing department have a spare Windows machine I can trade my Linux server for :p
rob
+2  A: 

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

Erik Dahlström
Well spotted! Unfortunately it didn't fix the problem, but thanks anyway.
rob