Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Access "RouteData" in the controller constructor

$
0
0

Hello:

Please see my sample code below. I'm trying to get the "TenantName" Route attribute defined at the Controller level.

In the controller constructor, I need to get the "TenantName" value.. How would I do that?

[Route("{TenantName}/api")]
public class SomeController : Controller
    {

      private readonly IConfiguration configuration;
      private IHostingEnvironment env;

public SomeController(IConfiguration configuration, IHostingEnvironment environment)
    {
         this.configuration = configuration;
         this.env = environment;
//HOW TO GET THE TENANT NAME {TenantName} HERE?
 //RouteData.Values["TenantName"]; DOESN'T WORK HERE BECAUSE ROUTEDATA IS NULL!
//WHAT KIND OF DI SHOULD I DO?
    }

}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>