Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Last active March 14, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/1f7d152646ca36b2f88079842a495c39 to your computer and use it in GitHub Desktop.
Save ornerymoose/1f7d152646ca36b2f88079842a495c39 to your computer and use it in GitHub Desktop.
if I set a breakpoint on this method and go to localhost:1234/api/employee, the breakpoint will be hit. If I try to do localhost:1234/api/employee/SOME_ID it'll 404. What am I overlooking here?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using MyApp.ElasticData;
using MyApp.Models;
namespace MyApp.Controllers
{
public class EmployeeController : BaseController
{
[Route("api/employee")]
[HttpGet]
public async Task<Employee> GetByPernr(string id = null)
{
var app = new ElasticEvents();
var emp = await app.GetElasticDataById(id);
var empData = new Employee
{
FirstName = emp.FirstName,
LastName = emp.LastName,
NtId = emp.NtId
};
return empData;
}
}
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment