Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net Core mvc hide and exclude Web Api Controller Method

I know there is the ApiExplorerSettings attribute

[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> MyMethod(int id)

But that does not stop a client of the api to call the endpoint method.

I need to know if there is an attribute that disables the endpoint and does not allow requests. I want to avoid doing it by modifying the routing mechanism.

like image 208
cnom Avatar asked Nov 16 '17 11:11

cnom


1 Answers

The simplest MVC approach might be to use the NonAction attribute, like so:

[ApiExplorerSettings(IgnoreApi = true)]
[NonAction]
public async Task<IActionResult> MyMethod(int id)

Another option is to just change the method's access modifier from public to e.g. private for the same effect.

If you'd like to exclude an entire controller, there's the NonController attribute:

[NonController]
public class MyController : ControllerBase
like image 142
Kirk Larkin Avatar answered Oct 05 '22 09:10

Kirk Larkin