title: How to find just one group a user is logged in as
body: <p>I have the following code which displays each group a user is logged in:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          Groups();
      }
  
      public ArrayList Groups()
      {
          ArrayList groups = new ArrayList();
  
          foreach (System.Security.Principal.IdentityReference group in
  
              System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
          {
  
              groups.Add(group.Translate(typeof
  
                  (System.Security.Principal.NTAccount)).ToString());
  
          }
          for (int i = 0; i &lt; groups.Count; i++)
          {
              MessageBox.Show(groups[i].ToString() + "");
          }
  
  
          return groups;
      }
  </code></pre>
  
  <p>Some of the groups that displays are:</p>
  
  <pre><code>BUILIN\Administrators
  Everyone
  IIS_Usrs
  tmg\IT Members
  tmg\Domain Users
  </code></pre>
  
  <p>How do I check if a user is in the <code>tmg\IT Members</code> group only?</p>
  
  <p>I tried the following but it failed because some group didn't have the <code>\</code>:</p>
  
  <pre><code>for (int i = 0; i &lt; groups.Count; i++)
          {
              MessageBox.Show(groups[i].ToString() + "");
              string t = groups[i].ToString().Split('\\')[0];
              string y = groups[i].ToString().Split('\\')[1];
              MessageBox.Show(t);
              MessageBox.Show(y);
          }
  </code></pre>