phicon phicon - 1 year ago 111
ASP.NET (C#) Question

ASP Core Azure Active Directory Login use roles

I created an Azure Active Directory Application and i want to use role based security. I followed the tutorial on:

The login works, I added roles to the application manifest and assigned the role

to my own account. Now i want to use these roles.

After login the following works in the controller:


But when adding the role the user is not authorized:


Also the following returns false:


It seems the roles are not retreived, any suggestions on how to add the role functionality to this demo project?

Answer Source

This code sample works for me after assign roles to account . Please debug application in this line: User.IsInRole("Approver"); , check whether { Approver}exists in user claims . And make sure you add roles which allowedMemberTypes is user , for example :

      "allowedMemberTypes": [
      "displayName": "Approver",
      "id": "fc803414-3c61-4ebc-a5e5-cd1675c14bbb",
      "isEnabled": true,
      "description": "Approvers have the ability to change the status of tasks.",
      "value": "Approver"

And you have assign the user role in Enterprise applications-->All applications--> find your app-->Users and groups--> add/edit a user and assign roles : enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download