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

Mar 30, 2010 at 10:15 AM

Hi

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() {

alert($().SPServices.SPGetCurrentUser());
       
             
    });

Anybody got any idea?

Thank you,

-Arun

Coordinator
Mar 30, 2010 at 12:43 PM

Arun:

Also see this post http://spservices.codeplex.com/Thread/View.aspx?ThreadId=207059&ANCHOR#Post423259

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.

M.

Apr 1, 2010 at 3: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
Coordinator
Apr 1, 2010 at 3: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.

M.

Apr 1, 2010 at 3:37 PM

Mark,
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

Coordinator
Apr 2, 2010 at 2:27 PM

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

M.

Apr 5, 2010 at 3:31 AM

Mark,

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
Coordinator
Apr 5, 2010 at 1:32 PM

Arun:

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.

Thanks!
M.