title: How to programatically check if a user can access a SharePoint site?
body: <p>I have a service that runs on the save server as SharePoint. I can use this service to upload/move files in document libraries on different SharePoint sites. I am now trying to check if a user (DOMAIN\USER) has permissions to access a particular SharePoint site.</p>
  
  <p>I have tried using the following:</p>
  
  <pre><code>web.EnsureUser("DOMAIN\USER")
  web.CheckPermissions(SPBasePermissions.Open)
  </code></pre>
  
  <p>The above should raise UnauthorizedAccessException if the user has no permissions. For me it never raises any exception although that user does not have permissions to access this particular site (verified by trying to access the site on the user's machine - Unauthorized 401)</p>
  
  <p><code>web.DoesUserHavePermissions("DOMAIN\USER", SPBasePermissions.Open)</code></p>
  
  <p>The above should return True or False, but for me it always returns False, also when the user has permissions to access a site (verified by accessing the site on the user's machine - OK 200).</p>
  
  <p><code>web.GetUserEffectivePermissions("DOMAIN\USER")</code></p>
  
  <p>The above should return the permissions mask, but it always returns an EmptyMask.</p>
  
  <p>I think I do not understand those methods, but they are not described well anywhere on the Internet.</p>
  
  <p>Does anyone know how I can check if a user has permissions necessary to access a SharePoint site?</p>