27

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.

0

1 Answer 1

78

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
Sign up to request clarification or add additional context in comments.

3 Comments

Is it possible to set IgnoreApi to true for all controllers? I have more controller that I need to hide right now.
@HungryWolf This might be helpful.
Used this today to replace the parameter used in an overriden controller method by setting the override to NonAction the aspcore router happily routes to the new method without an ambiguity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.