Matthew Verstraete
Matthew Verstraete

Reputation: 6781

Displaying user role in Forms Auth environment

I know you can use User.IsInRole to check to see if a user is in a specific role but is there a way to display what role the user is in when you don't know the role names?

Upvotes: 0

Views: 26

Answers (1)

David Tansey
David Tansey

Reputation: 6023

The ASP.NET Roles Provider has a method to return all Roles for the current user or for a specified UserName.

string[] rolesArray;
rolesArray = Roles.GetRolesForUser();

It is worth noting that if you call the method with no UserName parameter AND there is currently no one signed in (Anonymous access) then the method will THROW an exception.

Here are links to doc for both call variations:

http://msdn.microsoft.com/en-us/library/8ak75t41(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/8h930x07(v=vs.110).aspx

Upvotes: 2

Related Questions