# ASP.NET Web API2 Framework 4.5.2 access app\_metadata

**URL:** <https://community.auth0.com/t/asp-net-web-api2-framework-4-5-2-access-app-metadata/8870>\
**Category:** Get Help\
**Tags:** app\_metadata, .net\
**Created:** [December 2, 2017, 7:42am UTC](https://community.auth0.com/t/asp-net-web-api2-framework-4-5-2-access-app-metadata/8870 "2017-12-02T07:42:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamaero](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@adamaero](https://community.auth0.com/u/adamaero)\
**Post date:** [December 2, 2017, 7:42am UTC](https://community.auth0.com/t/asp-net-web-api2-framework-4-5-2-access-app-metadata/8870/1 "2017-12-02T07:42:53Z")

</div>

I can’t figure out how to access app\_metadata property in my controller ([ASP.NET](http://ASP.NET) WebAPI 2) .  
I added CMP\_KEY in app\_metadata for all users…

Here is what I’ve tried so far:  
//get userID from access\_token(WORKS !):  
var claimsIdentity = User.Identity as ClaimsIdentity;  
string userID = claimsIdentity.Claims.FirstOrDefault(c =\> c.Type == System.IdentityModel.Claims.ClaimTypes.NameIdentifier).Value;  
//get CMP\_KEY from Auth0 app\_metadata (NOT WORKING - ALWAYS Null)  
string lc\_cmp\_key = claimsIdentity.Claims.FirstOrDefault(c =\> c.Type == “https://my\_domain.com/CMP\_KEY”)?.Value;  
string lc\_cmp\_key2 = claimsIdentity.Claims.FirstOrDefault(c =\> c.Type == “CMP\_KEY”)?.Value;  
string lc\_cmp\_key3 = ClaimsPrincipal.Current.FindFirst(“CMP\_KEY”)?.Value;

Any help appreciated !

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [December 4, 2017, 8:01pm UTC](https://community.auth0.com/t/asp-net-web-api2-framework-4-5-2-access-app-metadata/8870/2 "2017-12-04T20:01:43Z")

</div>

Have in mind that you should add the custom claims you want to be available in the access token through rules; it is not enough to add a property to the `app_metadata`. From the provided information it is not clear if you really setup the rule or not.

I tried with my local environment which is running ASP .NET Web API 2 in OWIN and it worked as expected.

In particular, if I added the following rule to the list of rules to be executed:

```
function (user, context, callback) {
  context.accessToken"https://example.com/CMP_KEY"] = "CMP01";
  
  callback(null, user, context);
}

```

Proceeded to perform an end-user login that requested an access token for my API (used a resource owner password credentials grant for simplicity) I obtained an access token with this payload:

```
{
  "https://example.com/CMP_KEY": "CMP01",
  "iss": "https://[your_domain].auth0.com/",
  "sub": "auth0|5a2532444778270fa",
  "aud": "https://dotnetowinapi.example.com",
  "iat": 1512387660,
  "exp": 1512474060,
  "azp": "kPtiQTNwnhwqEwYFQ2NFtfUiIG",
  "scope": "read:values create:values",
  "gty": "password"
}

```

Finally, after configuring the API to process the access token issued by my Auth0 service and adding the authorize attribute to my controller I was able to access my custom claim using:

```
string key = ClaimsPrincipal.Current.Claims.FirstOrDefault(c => c.Type == "https://example.com/CMP_KEY")?.Value;

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:57am UTC](https://community.auth0.com/t/asp-net-web-api2-framework-4-5-2-access-app-metadata/8870/3 "2018-03-02T05:57:37Z")

</div>


