i have problem with my webapi controller, can not make it work correctly....
What is wrong?
Here the code:
WeabiConfig.cs
EnableCrossSiteRequests(config);
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "Api",
routeTemplate: "api/{controller}/{key}",
defaults: new { key = RouteParameter.Optional }
);
// this i added
config.Routes.MapHttpRoute(
name: "Action",
routeTemplate: "api/{controller}/{action}"
);
MyController:
[ActionName("TransformXMLToHTML")]
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.HttpGet]
public IHttpActionResult TransformXMLToHTML()
{
string xsltString = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Xml/inputXslt.xslt"));
string inputXml = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Xml/inputXml.xml"));
XslCompiledTransform transform = new XslCompiledTransform();
using (XmlReader reader = XmlReader.Create(new StringReader(xsltString)))
{
transform.Load(reader);
}
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(inputXml)))
{
transform.Transform(reader, null, results);
}
return Ok(results.ToString());
}
GET Request: http://localhost:60674/api/comments/TransformXMLToHTML
Error: No action was found on the controller 'Comments' that matches the request
Thanks guys!