You specified the route pattern URL, but did not mention what controller/action should handle these type of requests.
You may specify the defaults options when defining the route
app.UseMvc(routes =>
{
routes.MapRoute(
name: "beacon",
template: "beacon/{id?}",
defaults: new { controller = "Beacon", action = "Index" }
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Assuming your Index method has a id parameter of nullable int type
public class BeaconController : Controller
{
public ActionResult Index(int? id)
{
if(id!=null)
{
return Content(id.Value.ToString());
}
return Content("Id missing");
}
}
Another option is to remove the specific route definition from the UseMvc method and specify it using attribute routing.
public class BeaconController : Controller
{
[Route("Beacon/{id?}")]
public ActionResult Index(int? id)
{
if(id!=null)
{
return Content(id.Value.ToString());
}
return Content("Id missing");
}
}
The reason, http://www.example.com/beacon is working is because that request structure matches to the pattern defined for the default route.
Indexaction method inside BeaconController accepting an inputidparameter of type integer?