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?
 
Daniel Van Der WerkenConnect With a Mentor Independent 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.