Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Sometimes the code does not find the user details from User profile. It simply checks the profileManager.UserExists(userName[1]) and unable to fetch the user and executes the else part.

This issue is not regular.Most of the times it fetch the same user data correctly but sometimes fails.

What could be the possible reason of this and how to write it in the logs?

SPSecurity.RunWithElevatedPrivileges(delegate()<br />
             {<br />
                 using (SPSite site = new SPSite(SPContext.Current.Site.Url))<br />
                 {<br />
                     //ServerContext object current site<br />
                     ServerContext context = ServerContext.GetContext(site);<br />
                     //UserProfileManager object to access MOSS user profiles<br />
                     UserProfileManager profileManager = new UserProfileManager(context, false);<br />
                     string[] userName;<br />
                     userName = objUserUtility.GetCurrentUserLoginName().Trim().Split('\\');<br />
<br />
                     WriteToLog(userName[1].ToString());<br />
<br />
 if (profileManager.UserExists(userName[1]))<br />
<br />
{<br />
WriteToLog("Entered Inside");<br />
WriteToLog(userName[1].ToString());<br />
}<br />
else<br />
<br />
{<br />
lblUserExist.Visible = true;<br />
                         lblUserExist.Text = "You are not configured in the Application";<br />
}<br />
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900