我想在我的C#Web Api中使用Hateoas。如果被请求者通过提供路由名称可以访问其他路由,我希望能够解决。
PolicyB
而不是PolicyC
时,我希望他们接收“获取”,而不是“发布”PolicyB
和PolicyC
时,我希望他们接收“获取”和“发布”回来以下是示例代码:
public class AController : Controller
{
[HttpGet("A", Name = "RouteA")]
public IActionResult GetA()
{
IEnumerable<string> routesAbleToAccess = MethodsUserCanAccessForRoute("RouteB");
return Ok(routesAbleToAccess);
}
[HttpGet("B", Name = "RouteB")]
[Authorize("PolicyB")]
public IActionResult GetB()
{
return Ok();
}
[HttpPost("C")] // Also named Route B
[Authorize("PolicyC")]
public IActionResult SaveC()
{
return Ok();
}
private IEnumerable<string> MethodsUserCanAccessForRoute(string route)
{
// logic to get the routes that the user can access
}
}