SPGetCurrentUser returns previous user login

Mar 24, 2010 at 5:54 PM

I am using the SPServices.SPGetCurrentUser() in a content editor web part (version 0.5.3) . If I initially log in as User1,  the correct user is returned.  However, if I subsequently login as a User2, it still returns User1 as the current user.  If I close the browswer, then open it again as User2, the correct user is returned. my code snippet is below.  Am I doing something incorrectly?  How can I force the it to return the "current" user regardless of who logged in previously?  thanks

<script type='text/javascript'>
var isPM = 'No';
var isDelivery = 'No';
var isDesign = 'No';
$(document).ready(function()
{
$().SPServices({
  operation: "GetGroupCollectionFromUser",
  userLoginName: $().SPServices.SPGetCurrentUser(),
  async: false,
  completefunc: function(xData, Status) {
    if($(xData.responseXML).find("Group[Name='CPDNet_PM']").length == 1)
    {
     isPM = 'Yes';
	 isDelivery = 'Yes';
	 isDesign = 'Yes'
    }
	if($(xData.responseXML).find("Group[Name='CPDNet_Design']").length == 1)
	{
	  isDesign = 'Yes';	  
	}
	if($(xData.responseXML).find("Group[Name='CPDNet_Delivery']").length == 1)
	{
	  isDelivery = 'Yes';	  
	}
	if($(xData.responseXML).find("Group[Name='CPDNet_Stakeholders']").length == 1)
	{
	  isDesign = 'Yes';	  
	}
   }
});
}
);
</script>

 

Coordinator
Mar 24, 2010 at 6:50 PM
Edited Mar 24, 2010 at 6:50 PM

What you are doing should definitely work the way you want it to.

See this thread from yesterday, as someone else was asking the same thing. http://spservices.codeplex.com/Thread/View.aspx?ThreadId=207059 I show the function and explain how it works there.

When you are logging in as the second user, what mechanism are you using? Is this MOSS or WSS?

M.

Mar 24, 2010 at 8:14 PM

Moss 2007

changing user from the UI menu "Sign in as Different User".  If I choose "Sign Out" first (which closes the page), then sign back in as a different user, it functions as expected.  I guess sharepoint doesn't sign out the current user when going down the path "Sign in as Different User"? 

Coordinator
Mar 24, 2010 at 9:57 PM

When you change users, does the Welcome Message at the top of the page display the second user?  What about after you refresh the page again?

I've seen this from time to time, but I've never understood it.  I just posted a question about it over on SharePointOverflow.com.

Because of the way I'm getting the current user, I don't think we can consider it a bug with my code (I'd admit it if it were), but obviously it's a problem for you. Let's see what we hear over on SPOverflow.  Feel free to add your $.02 on the question.

M.

Mar 24, 2010 at 10:31 PM

Yes, that's what had me banging my head on the wall - the screen would tell me the user had changed  but jquery would tell me otherwise.  Sometimes it will take a screen refresh to update the screen to the new user but even so, the jquery would still indicate the previous user.   thanks for assistance.  Dan