Get current logon user id with SPContext.Current.Web.CurrentUser. LoginName
Hi all,I've been trying to search for the methodto display the currently logon user id. So far,most sites I've visited used SPContext.Current.Web.CurrentUser.LoginName.I've tried this in my SharePoint custom application page. Everything works great.I have a test account, when logged in, was displayed as xxx\testacc.For some reasons, I changed the id in AD to xxx\test and did a full import to MOSS.I logged in to the custom application with the changed id, i.e. xxx\test, BUT the value of SPContext.Current.Web.CurrentUser.LoginName still displayed as xxx\testacc!How do I get the latest id? Has anyone encountered this before?Thank you.Kelvin
September 12th, 2008 4:38am
kelvin,If you run stsadm -o migrateuser (http://technet.microsoft.com/en-us/library/cc262141.aspx) for this account it should get your change back in sync. This tool migrates an existing sharepoint account into a new login (eg when a name and account is changed after marriage).Regards,Josh Carlisle
Free Windows Admin Tool Kit Click here and download it now
September 12th, 2008 6:20am
Hi Josh,Thank you for your reply.I tried stsadm -o migrateuser -oldlogin xxx\testacc -newlogin xxx\test but I got this error instead. "New user account does not have value SID history". Any step or commandthat I've left out?Thank you in advance!Kelvin
September 16th, 2008 6:08am
Ok I've tried using stsadm -o migrateuser -oldlogin xxx\testacc -newlogin xxx\test -ignoresidhistory and it worked fine.But SPContext.Current.Web.CurrentUser.LoginName still displayed the old value.I checked value of tp_Login in UserInfo found in the content DB, it's still showing the old value instead.Any other way that I can update this value without direct update to the DB?Help, anyone? Thank you
Free Windows Admin Tool Kit Click here and download it now
September 17th, 2008 5:51am
More of an admin question then a developer question.. moving Posting is provided "AS IS" with no warranties, and confers no rights.
September 17th, 2008 5:53pm
Interesting that. I came into the thread to move it to Programming ...Surely asking a question about a method is Programming ?The replies on the other hand seem to be about stsadm which is for sure Admin.I'm confused. Surely what the question is defines the forum - rather than the answers which seem to somewhat avoiding the question.
Free Windows Admin Tool Kit Click here and download it now
September 17th, 2008 5:59pm
I still think it should be under Development.. from where I'm coming from.. :)
September 19th, 2008 5:25am
I too have the same problem with text.Current.Web.CurrentUser.LoginName. Sometimes It is returning the login name user which is other than current logged in user..
http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/b8815101-c8c7-4123-b568-fd39de29a02d
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2010 7:46pm