0

When using attribute routing, is it possible to remove routes based on certain runtime condition - such as licensing?

Something like this:

[LicensedRoute("/api/whatever")]

where '/api/whatever' is only added to the route table if the application is licensed.

Obviously I can explicitly do the check in the action method or use an action filter to validate the requests but ultimately I prefer the route not to be available if the software is not licensed.

1
  • 1
    Probably custom authorization attribute is more relevant in this case. Commented Jul 5, 2016 at 17:44

1 Answer 1

1

Seems you need Attribute Routing: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

Is it RESTful? How you store the licensing info: is it user logins? tokens? key?

You could do it RESTful and force the client to pass a token every time via token-based authentication, for example: define several "licence" levels/types (eg. Free/Trial/Basic/Pro) and then in a persistent storage (table) map tokens (guids) to a licence type.

Then using a custom attribute, mark each endpoint/controller/action with the minimum required licence type to be accessible (e.g. [MinimumLicence("Basic")]). And then create "routing tables" based on the licence required.

In this case you would deny access to routes rather than "remove" them.

Sign up to request clarification or add additional context in comments.

1 Comment

So the short answer is No.

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.