I am trying to implement HMAC authentication using the code given here: http://bitoftech.net/2014/12/15/secure-asp-net-web-api-using-api-key-authentication-hmac-authentication/.
I integrated this code inside my ASP.NET web forms application. I created a folder named "HMACAPI" and added the controllers and filters inside it. I also installed all the required Nuget packages. This is how I am implementing my service methods:
[HMACAuthentication]
[RoutePrefix("api/forms")]
public class FormsController : ApiController
{
[Route("")]
public IHttpActionResult Get()
{
ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
var Name = ClaimsPrincipal.Current.Identity.Name;
return Ok("test");
}
[Route("")]
public IHttpActionResult Post(string order)
{
return Ok(order);
}
}
This is my route configuration for the API:
GlobalConfiguration.Configure(APIWebFormsProject.API.WebApiConfig.Register);
But when I use client.PostAsJsonAsync()
, it's showing Method Not Allowed
error. I tried various SO questions but none of their answers are helping.
What I tried:
Removed
WebDAV
module.Added
[HttpPost]
attribute to post method.
I am using "http://localhost:56697/api/forms/" URL to access the API. But I also tried "http://localhost:56697/api/forms" and "http://localhost:56697/api/forms/test".
GlobalConfiguration.Configuration.Routes.MapHttpRoute
instead ofRouteTable.Routes.MapHttpRoute
– MethodMan Oct 10 at 16:25Method Not Allowed
error. – Aishwarya Shiva Oct 10 at 16:32