Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static SPUser Find(SPWeb inWeb, string loginName)
- {
- try
- {
- if (string.IsNullOrEmpty(loginName))
- return null;
- string searchedLogin = loginName;
- SPWeb web = inWeb.IsRootWeb ? inWeb : inWeb.ParentWeb;
- SPUser result = null;
- SPSecurity.RunWithElevatedPrivileges(delegate
- {
- using (var elevatedSite = new SPSite(web.Site.ID))
- {
- using (var elevatedWeb = elevatedSite.OpenWeb(web.ID))
- {
- result = elevatedWeb.EnsureUserUnsafe(searchedLogin);
- }
- }
- });
- return result;
- }
- catch
- {
- return null;
- }
- ------------------------------
- public static SPUser EnsureUserUnsafe(this SPWeb web, string logonName)
- {
- UnsafeUpdate uu = null;
- try
- {
- uu = new UnsafeUpdate(web);
- return web.EnsureUser(logonName);
- }
- catch (SPException ex)
- {
- throw new SPException("error ensure user " + logonName, ex);
- }
- finally
- {
- if (uu != null)
- {
- uu.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement