mercredi 23 octobre 2019

Web API RoutePrefix does not allow

Blockquote [RoutePrefix("3pi/venue/1.0")] public class ProductsController : ApiController { Product[] products = new Product[] { new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } };

    [Route("")]
    public IEnumerable<Product> GetAllProducts()
    {
        return products;
    }

    [Route("{id:int}")]
    public IHttpActionResult GetProduct(int id)
    {
        var product = products.FirstOrDefault((p) => p.Id == id);
        if (product == null)
        {
            return NotFound();
        }
        return Ok(product);
    }
}

If I add [RoutePrefix("3pi/venue/1.0")] it does not work, but when I add [RoutePrefix("3pi/venue/10")] (remove .) it work. How to fix this issue




Aucun commentaire:

Enregistrer un commentaire