This project has moved and is read-only. For the latest updates, please go here.

SPGetCurrentUser fails while using "Login as another user" menu item

Mar 30, 2010 at 11:15 AM


I am using $().SPServices.SPGetCurrentUser() to get the current user login. It works fine when the user logs into the system from a new browser window. But once logged in, when he tries to login as another user by selecting the top-right menu, this method fails. It still keeps the previous username. Here is a code i am using.

$(document).ready(function() {


Anybody got any idea?

Thank you,


Mar 30, 2010 at 1:43 PM


Also see this post

Is this something that you are running into only in testing? I agree it's an issue, but I think it's actually SharePoint and not my code causing the issue.


Apr 1, 2010 at 4:12 PM
Hi Mark, Mark, it looks like IE is caching the page userdisp.aspx. I had the same issue. A quick workaround for IE 8 is set value of "Internet Options > Browsing History > Settings > Temporary Internet Files > Check For newer version of stored pages" to "Everytime I visit the webpage". I don't think this is a solid solution, but it worked for me. Hope this helps Arun D. Gangadharan
Apr 1, 2010 at 4:16 PM

Yes, that solves it on a client by client basis, but it doesn't make the function correct, unfortunately.  I'm not sure what to do about this.  The only silver lining is that switching identities isn't something that most users ever do.

What I need is some way to force the page to do a hard refresh in the script.

It's a pretty significant flaw in SharePoint, IMHO.


Apr 1, 2010 at 4:37 PM

What do you think? Is it a problem with SharePoint (i. e. its rendered HTML) or IE. I think it's IE because it works with above cache setting. Also I don't see this kind of problem with my Firefox.

-Arun D Gangadharan

Apr 2, 2010 at 3:27 PM

Regardless where the problem's genesis is, if my function returns the wrong answer, then it's my problem.


Apr 5, 2010 at 4:31 AM


I just tried a small workaround and it seems working for me. This is based on browser url cheat.

I modified the script so that for opening userdisp.aspx, a dynamic query string also gets attached to the page url. Idea is to make the browser think that its a fresh request and get the fresh page from server.

Take a look at this code, not sure this is a right approach.

url: $().SPServices.SPGetCurrentSite() + "/_layouts/userdisp.aspx?Force=True"+"&"+new Date().getTime(), // Force parameter forces redirection to a

-Arun D Gangadharan
Apr 5, 2010 at 2:32 PM


So elegantly simple!  I probably would never have thought of it.

I just tried this in my test environment, and it does indeed seem to work.  In fact, SPGetCurrentUser is returning the right user even when the SharePoint page is showing the prior user.  Slick!

I'm going to put this into the next alpha.  It certainly can't hurt anything, and hopefully it is a true fix.