Menu
Download Free Trial

Saving to server not working…

Answered

Please advice on a solution. This example is provided to save to server in API documentation
flexmonster.save('myreport.xml', 'server', '', 'http://yourserver.com/yourscript.php');
We are attempting:
flexmonster.save('myreport.xml', 'server', '', 'http://ourserver:54422/savereport.aspx');
and flexmonster reports “error! can not save file”. The aspx page attempts to save the incoming HTTP post to a local file and has been tested. When running in a debug environment we can set a breakpoint and confirm http://ourserver:54422/savereport.aspx never gets called.
 

5 answers

Public
Roman Petrusha Flexmonster March 22, 2016

Hi!

Probably you have a security issue. Please check if CORS is enabled on your server.
I recommend you to use a tool like (Fiddle) to server’s response.

Public
Jeremy Deats March 23, 2016

Thank you! It turned out to be CORS and another setting I had to change to allow ASP.NET to accept the request format. For other .NET developers I’ll share the web.conf changes I had to set in order to enable this. Now I have to figure out how to decompress the GZIP string
 
<configuration>
  <system.web>
    <customErrors mode=”Off”/>
    <compilation debug=”true” targetFramework=”4.0″/>
    <!– requires because the Microsoft’s request objects don’t play friendly http post with header sequences they don’t reconize –>
    <httpRuntime requestValidationMode=”2.0″/>
    <!– validateRequest=”false” also added for this reason –>
    <pages validateRequest=”false” controlRenderingCompatibilityVersion=”3.5″ clientIDMode=”AutoID”/>
  </system.web>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <!– this enables CORS –>
        <add name=”Access-Control-Allow-Origin” value=”*” />
      </customHeaders>
    </httpProtocol>
    <httpErrors errorMode=”Detailed”/>
  </system.webServer>
</configuration>

Public
Iryna Kulchytska Flexmonster March 23, 2016

Hi Jeremy,
 
Thank you very much for sharing web.conf for other .NET developers.
Please let us know if you need any further assistance.
 
Kind regards,
Iryna

Public
Jeremy Deats March 23, 2016

Thank you ira!
Also posting the C# ASP.NET source to handle the capture. I took this approach because I’m embedding in a WebForms project, but I hope someone finds this useful.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.IO.Compression;
using System.Text;

namespace FlexDemo
{
    public partial class CaptureDoc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             
            try
            {
                int lineCount = 0;
                StringBuilder sb = new StringBuilder();

          
                using (StreamReader sr = new StreamReader(Request.InputStream))
                {
                    string line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        sb.Append(line);
                        lineCount++;
                    }
                }

                string xml = sb.ToString();
                string dxml = Server.UrlDecode(xml);

                // remove unwanted name-value pairs
                dxml = dxml.Replace(“name=myreport.xml&report=”, “”);
                dxml = dxml.Replace(“&type=xml”,””);
                
                // write report to hard drive
                System.IO.File.WriteAllText(@”c:\temp2\flex.xml”, dxml);

                Response.Clear();
                Response.Write(“<response><status>Success</status><message>Wrote ” + lineCount.ToString() + ” lines</message></response>”);
                Response.End();
            }
            catch (Exception exc)
            {

                Response.Clear();
                Response.Write(“</response><status>Fail</status><exception>” + exc.Message.ToString() + “</exception></response>”);
                Response.End();
            }
             
        }
    }
}

Public
Iryna Kulchytska Flexmonster March 24, 2016

Hi Jeremy,

Thank you so much for posting the solution. We really appreciate this and are happy that you are contributing to the knowledge around our component.

Thank you,
Iryna

Please login or Register to Submit Answer