title: Are there better (easier) ways to get a specific domain's SID?
body: <p>I've been assigned to modify a WinForms application to basically check that the logged on user belongs to a specific domain.
  This is what I've come up with so far:</p>
  
  <pre><code>byte[] domainSid;
  
  var directoryContext =
      new DirectoryContext(DirectoryContextType.Domain, "domain.se");
  
  using (var domain = Domain.GetDomain(directoryContext))
  using (var directoryEntry = domain.GetDirectoryEntry())
      domainSid = (byte[])directoryEntry.Properties["objectSid"].Value;
  
  var sid = new SecurityIdentifier(domainSid, 0);
  bool validUser = UserPrincipal.Current.Sid.IsEqualDomainSid(sid);
  </code></pre>
  
  <p>Is there a better/easier way to do this?
  To me it seems like the domainSid would be accessible in some way using the PrincipalContext or some other class in System.Security.Principal.</p>
  
  <p>I've considered using a hardcoded SID-string, but I don't know how "correct" that would be.</p>