I am creating an API using ASP.NET Core, and below is my controller code.
I have given the controller and Startup code below, along with fiddler request/response log. I am getting a 404 Not Found error. Please advise what am I missing?
[Route("api/[controller]")]
public class UserController : Controller
{
[HttpPost]
public string RegisterUser(User newUser)
{
// Code to register user in system
return succecss/failure message
}
}
I tried suggested attribute routing from https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing but still no luck. I am not sure what I am missing.
Please note that with the Web API template , there is no default routing in Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
The following is my fiddler request:
URL: http://localhost:8011/api/User/RegisterUser
Verb= post
User-Agent: Fiddler
Host: localhost:8011
Content-Type: application/json
Content-Length: 77
Request body
{"FirstName": "TEST FirstName", "LastName": "Test Last Name", "EmailId":"[email protected]","Password":"1"}
Output in response header:
HTTP/1.1 404 Not Found