I'm trying to use the web api in c# so far its been working pretty well but i just have a route that doesn't want to work and i searched a bit around for people with similar problems but their solution didn't seem to work. I'm trying to have a specific route and capturing an email address in the string, here is my Controller:
[Authorize] [RoutePrefix("api/contact")] public class ContactController : ApiController { [Route("list/{id:int}")] [HttpGet] public ContactList GetList(int id) { BasicAuthenticationIdentity identity = (BasicAuthenticationIdentity)this.User.Identity; ContactModel contactModel = new ContactModel(identity.accountId); return (contactModel.GetList(id)); } [Route("list/{id:int}")] [HttpPost] public void PostList(int id) { BasicAuthenticationIdentity identity = (BasicAuthenticationIdentity)this.User.Identity; // To be implemented } [Route("attribute/{contactKey}")] [HttpGet] public IEnumerable<ContactData> GetContactAttributeKey(string contactKey) { BasicAuthenticationIdentity identity = (BasicAuthenticationIdentity)this.User.Identity; ContactModel contactModel = new ContactModel(identity.accountId); return (contactModel.GetContactAttribute(contactKey)); } } The list route works well but when i try something like http://localhost/api/contact/attribute/[email protected] i keep getting HTTP Error 404.0 - Not Found because it seems it can't find the route. Is there something wrong in this?
I also have this in the webconfig
// Itinéraires de l'API Web config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); I tried to see if other routes could be set that are the same but there is no other, i just have an account and segment route other than that, if anyone got some suggestion i'm open to everything right now :/