[HttpGet("~/areas/location/{id:int}", Name = "Get Locations")] //Here Name attribute is same as below route also.
[HttpGet("~/location/{id:int}", Name = "Get Locations")] //route name aslo same ("Get Locations")
public async Task<IActionResult> Getlocation(int id)
{
_linksService.AddLinksAsync(locationmodel);
// Already we have
}
we are aware that , route Name attribute cannot be support same name with more than one route. Expected:
[HttpGet("~/areas/location/{id:int}")] //-- Here We will remove that Name attribute and instead of that we will pass that text in another parameter as below stated.[HttpGet("~/location/{id:int}")]
public async Task<IActionResult> Getlocation(int id)
This is not an enhancement I would make. If you want to submit a pull request for it, please feel free and I'll merge it in if appropriate. I would want to see tests covering the scenario.
Scenerio:
[HttpGet("~/areas/location/{id:int}", Name = "Get Locations")] //Here Name attribute is same as below route also.
[HttpGet("~/location/{id:int}", Name = "Get Locations")] //route name aslo same ("Get Locations")
public async Task<IActionResult> Getlocation(int id)
{
_linksService.AddLinksAsync(locationmodel);
// Already we have
}
we are aware that , route Name attribute cannot be support same name with more than one route.
Expected:
[HttpGet("~/areas/location/{id:int}")] //-- Here We will remove that Name attribute and instead of that we will pass that text in another parameter as below stated.[HttpGet("~/location/{id:int}")]
public async Task<IActionResult> Getlocation(int id)
{
_linksService.AddLinksAsync(locationmodel,"Get Locations");
// Possible to pass Rel info (Or)
_linksService.AnotherExtensionMethod(locationmodel,"Get Locations");
// Possible to pass Rel info
}
Also, I have configured the Startup like below:
services.AddLinks(config =>
{
config.UseRelativeHrefs();
config.ConfigureRelTransformation(transform => transform.Add(ctx => $"{ctx.LinkSpec.RouteName}"));
config.AddPolicy<Location>("LocationsPolicy", policy =>
{
policy.RequireRoutedLink("users", "Get Locations", x => new { id = x.Id });
});
});
Output :
"_links": {
"users": {
"rel": "Get Locations",
"href": "/api/locations/1/users",
"method": "GET"
}
Problem: In this case i have to create indivitual policy for each action methods. N number of actions are there(with same name).
Can someone throw more light on how to resolve the issue?
Your help is much appreciated