1

Is possible to read Route Prefix value in C# web api controller. I tried out, but I couldn't find any way to access this.

[RoutePrefix("api/Account")]

How to get the value inside "" in to a variable.

Harsha W
  • 3,162
  • 5
  • 43
  • 77
  • 1
    Assuming you are inside controller: `this.GetType().GetCustomAttribute().Prefix;` – Evk Mar 16 '18 at 05:24

1 Answers1

1

RoutePrefix is regular .NET attribute, so you can reach it like this (assuming you are doing that from inside of controller):

// this.GetType() is type of current controller
var prefix = this.GetType().GetCustomAttribute<RoutePrefixAttribute>().Prefix;
Evk
  • 98,527
  • 8
  • 141
  • 191