Since I used SharePoint 2007, when I browse to “Sign in as Different user” menu to login with another account. But after login successful, I’m still see last user name at the top of page event if I tried to refresh many times. Maybe you have experience about this also.

The reason is SharePoint doesn’t clear asp.net session and cookie objects. These object should be clear after 30 seconds and all data will be correct.

After analyze this issues, “Sign in as different user” is built in Welcome.ascx user control under 12 hive folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES. This user control will call LoginAsAnother() javascript method in Init.js file under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033

Firstly, make a copy of Init.js file to make sure we can recover it when need. Open Init.js by a text editor, search for LoginAsAnother, add following line of code

document.execCommand(“ClearAuthenticationCache”);

After completed, the function should be like this:

function LoginAsAnother(url, bUseSource)
{
document.cookie="loginAsDifferentAttemptCount=0";
if (bUseSource=="1")
{
GoToPage(url);
}
else
{
var ch=url.indexOf("?") >=0 ? "&" : "?";
url+=ch+"Source="+escapeProperly(window.location.href);
STSNavigate(url);
//++Added by Hoang Nhut NGUYEN++//
document.execCommand("ClearAuthenticationCache");
}
}

Save the file and try to refresh the page. If you configured for BLOB caching, it’s necessary to restart IIS.

The limitation of this solution is Init.js file will be overwrite when an new installation of SharePoint service pack applied.

Any better solutions. Don’t hesitate to share.

Hoang Nhut Nguyen
Email: nhutcmos@gmail.com
Skype: hoangnhut.nguyen