I recently took ASP.NET API stuff, and although I have allowed authorization and authentication, I cannot crack routing. A nightmare!
I created an Authenticate() method with an AuthenticationController . I add the [HttpGet] attribute to Authenticate() , and yet whenever I get into the API, I get 404 .
Here is my current WebApiConfig : -
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute("DefaultApiWithId", "{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" }); config.Routes.MapHttpRoute("DefaultApiWithAction", "{controller}/{action}"); config.Routes.MapHttpRoute("DefaultApiGet", "{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }); config.Routes.MapHttpRoute("DefaultApiPost", "{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) }); }
And the address I'm trying to do is /authentication .
The controller looks like this: -
[BasicHttpAuthorize(RequireAuthentication = true)] public class AuthenticationController : ApiController { [HttpGet] public string Authenticate(string email, string password, string agent, string ip) { } }
Can someone direct me in the right direction please? I tried using multiple addresses / endpoints: -
/authentication/authenticate/authentication//authentication
source share