1

In our project I recently dumped a list of routes to controllers in order to learn a new asp.net project that I recently joined the team of.

However, they have a class used as an attribute in a namespace that is being picked up by asp.net as a controller class, which is registering 'null' / empty routes in the dump, named GenericController.

Is there a way to mark this class using attributes (Similar to marking methods using [NonAction]) as 'not a controller?' And if not, what alternatives are there for excluding 'matching by convention' named classes from being controllers?

Ryan Leach
  • 4,262
  • 5
  • 34
  • 71

1 Answers1

2

Is there a way to mark this class using attributes (Similar to marking methods using [NonAction]) as 'not a controller?'

  1. There's a built-in [NonControllerAttribute].
  2. Also, you can make your class a nested class, an abstract class, an internal class, a generic class , etc to avoid picking it as a Controller.

Fore more details, see Source Code

itminus
  • 23,772
  • 2
  • 53
  • 88
  • Will I run into issues with the 'derived types' if our 'genericController' attribute is applied to other controllers that we wish to be registered? – Ryan Leach Jan 23 '20 at 03:46
  • @RyanTheLeach As far as I know, the `[NonController]` attribute is only a marker attribute that indicates that class should not be be considered as a controller. It won't influence others. So IMO, it shouldn't result in that issue. – itminus Jan 23 '20 at 04:11