How to return a dynamic KML file for Google Earth (.NET MVC 3)
===

I have the next Method in a Controller


    public ActionResult LimitesCampo(int id)
    {
        var kml = fieldService.GetKml(id);

        FileInfo fileInfo = new FileInfo("Field" + id + ".kml");
        if (!fileInfo.Exists)
        {
            using (StreamWriter writer = fileInfo.CreateText())
            {
                writer.WriteLine(limites.KML);
            }
        }

        this.Response.AddHeader("Content-Disposition", "filename=" + Server.HtmlEncode("Field" + id + ".kml"));
        this.Response.ContentType = "application/vnd.google-earth.kml+xml";

        return File(fileInfo.OpenRead(), "application/vnd.google-earth.kml+xml");
    }


When I enter the URL of the Controller Action the KML is returned properly, even the browser ask for download file and works fine on Google Earth standalone application, but if I try to retrieve the KML from a jQuery AJAX function the KML doesn't work on the GE Plugin of my application. I tried with KML files stored on disk and works correctly, the problem is with dynamic data.

NOTE: I'm using the Web server integrated with Visual Studio 2010 Express.