Get user in role only

  HI, I have this bit of code that gets all roles.

But I only want to get roels App_survey.

How can I do this please?

 ddlRole.DataSource = Roles.GetAllRoles();
bailey1200Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel Van Der WerkenIndependent ConsultantCommented:
GetAllRoles() returns a string array.

Basically, you just want to return the role "App_Survey", is that right?

You already know the role name, so I don't see the point in dong a get for it.  Can you give more details?  Do you want to make sure it exists?

You would use bool RoleExists( string roleName ) for that.

However, if you want to use GetAllRoles() then you'll have to wrap it in another method.  Like:

public string GetyApp_SurveyRole()
{
   string app_survey = string.Empty;
   string[] allRoles = Roles.GetAllRoles();
   for ( int i = 0; i < allRoles.Length; i++ )
   {
      if ( string.Equals( allRoles[i], "App_Survey" )
      {
          app_survey = allRoles[i];
      }
   }

   return app_survey;
}

OR -- if you are writing your own role provider, you can create your own method in the Roles class.  I assume you're not doing this.  Otherwise, just write a method in the Roles class that does basically the same thing as above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.