5

According to the documentation (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx) the login is created when the provided login does not exist.

From what I have tested so far no account is created when using this method. I simply get an exception which has the message that the user does not exist.

Am I missing something or is the documentation not correct?

André
  • 446
  • 4
  • 16
  • Mu understanding of the documentation is this: if the login has access to the site collection, then the user is added to the site. – jpaugh Sep 20 '17 at 15:58

3 Answers3

5

It does not create a new account, but checks if the account has access to the site. If not and the user is valid, it adds the user to the site permission list of the specifice website

Remko
  • 3,277
  • 2
  • 22
  • 39
  • 1
    You're right. I've checked in List 'User Information List. Am I right that the user account is added to this list but no permissions are assigned?

    Is there any better way to check whether a user exists in a web?

    – André Oct 31 '13 at 08:43
1

Yes It do not create account. Please refer this: http://razaalimithani.blogspot.com/2013/02/sharepoint-2010-spcontextcurrentwebensu.html

0

The MSDN about SPWeb.EnsureUser is correct. Are you sure to run AllowUnsafeUpdates to true while executing SPWeb.EnsureUser on SPWeb object?

Falak Mahmood
  • 17,298
  • 2
  • 40
  • 67