Link to home
Start Free TrialLog in
Avatar of Pete2003
Pete2003

asked on

Streaming SVG in an ASPX page

Hi All,

I need some help.

I have an ASPX Page. I would like to stream a simple polygon in SVG.

I'v tried MANY combinations but with no luck
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "image/svg+xml";
            Response.Write("<?xml version=\"1.0\" standalone=\"no\"?>");
            Response.Write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");
            Response.Write("<svg width=\"12cm\" height=\"4cm\" viewBox=\"0 0 1200 400 xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">");
            Response.Write("<desc>Example polygon01 - star and hexagon</desc>");
            Response.Write("  <rect x=\"1\" y=\"1\" width=\"1198\" height=\"398\" fill=\"none\" stroke=\"blue\" stroke-width=\"2\" />");
            Response.Write("   <polygon fill=\"red\" stroke=\"blue\" stroke-width=\"10\" points=\"350,75  379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161\" />");
            Response.Write("</svg>");
            Response.End();
        }

I hav tried changing the type from image to text, taking out the XML and DOCTYPE and no luck.
I have the adobe viewer installed on IE6.


Any help appreciated
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

Your svg is not well formed.
It may be the namespaces you have eclared.

This works ;

private void Page_Load(object sender, System.EventArgs e)
            {

                  Response.AddHeader("Content-Type","image/svg-xml");
                  Response.Write("<svg width=\"12cm\" height=\"4cm\" viewBox=\"0 0 1200 400\">");
                  Response.Write("<desc>Example polygon01 - star and hexagon</desc>");
                  Response.Write("  <rect x=\"1\" y=\"1\" width=\"1198\" height=\"398\" fill=\"none\" stroke=\"blue\" stroke-width=\"2\" />");
                  Response.Write("   <polygon fill=\"red\" stroke=\"blue\" stroke-width=\"10\" points=\"350,75  379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161\" />");
                  Response.Write("</svg>");
                  Response.End();


            }
OK.
I have found the problem it is here :

 Response.Write("<svg width=\"12cm\" height=\"4cm\" viewBox=\"0 0 1200 400 xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">");

The attribute viewBox is not closed correctly you need it to be this :

 Response.Write("<svg width=\"12cm\" height=\"4cm\" viewBox=\"0 0 1200 400\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">");
If you look in your browser when you mouse-over the page the svg plug-in has actually set the status bar test to :

not well formed : line 1, column 195.

However, it just shows this as info, not and error or even a warning.
Avatar of Pete2003
Pete2003

ASKER

Thanks for the replies, unfortunatelly nothing worked ...

I tried copy & paste from your 1st reply, al I get is a blank SVG plugin window.
I also tried fixing the viewbox window, no change
ALso I get nothing on the status line when I mouse over.

If you look at this article and examples can you see the graphics ?

http://www.4guysfromrolla.com/webtech/091401-1.shtml
Ok this is very weird ...

The 1st demo shows nothing
<%Response.AddHeader "Content-Type","image/svg-xml"%>
<svg>
  <rect x="10" y="10" width="100" height="100"/>
</svg>



The 2nd one ...
<%Response.AddHeader "Content-Type","image/svg-xml"%>
<svg width="12cm" height="3.6cm" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <path id="MyPath"
          d="M 100 200
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
  </defs>
  <desc>Example toap01 - simple text on a path</desc>

  <use xlink:href="#MyPath" fill="none" stroke="red"  />
  <text font-family="Verdana" font-size="42.5" fill="blue" >
    <textPath xlink:href="#MyPath">
      <%
      Dim title
      title = "We go up, then we go down, then up again."
      If Request("title") <> "" Then
         title = Request("title")
      End If
      Response.Write title
      %>
    </textPath>
  </text>

  <!-- Show outline of canvas using 'rect' element -->
  <rect x="1" y="1" width="998" height="298"
        fill="none" stroke="blue" stroke-width="2" />
</svg>

Works 100% ... I tried uninstalling/rebooting and it's still the same
Very weird....
It turns out that none of the SVGs are visible on the same machie as VS2005 is installed and I'm debugging from, but once I connect to the IIS site from a remote machine then I can see the SVG.

Does anybody know what to do to get it visible on the same machine?
ASKER CERTIFIED SOLUTION
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked 100% thanks :)
OK. However, you should make sure you are fully patched.
The Vulnerability in the SVG dll was a zero-day, remote code execution vulnerability.
If you are not patched you could get a nasty shock.