Estoy aprendiendo a crear un complemento ppt de acuerdo con el tutorial oficial . Seguí los pasos de la sección Insertar una imagen , pero descubrí que el complemento no funcionaba correctamente. Cuando hice clic en el botón "Insertar imagen", el complemento visitó /api/Photo/ a través de ajax, pero el código de estado siempre fue 404.
Esta es la función llamada cuando hice clic en el botón:
function insertImage() { // Get image from from web service (as a Base64 encoded string). $.ajax({ url: "/api/Photo/", success: function (result) { insertImageFromBase64String(result); }, error: function (xhr, status, error) { // always 404 showNotification("Error", "Oops, something went wrong."); } }); }Y este es el ApiController:
namespace HelloWorldWeb.Controllers { public class PhotoController : ApiController { public string Get() { string url = "http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1"; // Create the request. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); WebResponse response = request.GetResponse(); using (Stream responseStream = response.GetResponseStream()) { // Process the result. StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); string result = reader.ReadToEnd(); // Parse the xml response and to get the URL. XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string photoURL = "http://bing.com" + doc.SelectSingleNode("/images/image/url").InnerText; // Fetch the photo and return it as a Base64 encoded string. return getPhotoFromURL(photoURL); } } private string getPhotoFromURL(string imageURL) { var webClient = new WebClient(); byte[] imageBytes = webClient.DownloadData(imageURL); return Convert.ToBase64String(imageBytes); } } }Me pregunto cómo puedo configurar los enrutadores. No se ha discutido en el tutorial y estoy confundido si se configura automáticamente.
¡Gracias!