SharePoint used to have a menu option called "Sign in as Different User" in the top-right corner of every page. It was a handy tool for developers and IT professionals in SharePoint 2007 and 2010, which allowed them to login with another account to test their solutions or customizations. Microsoft removed the option in SharePoint 2013, but you can still do it with workarounds or a one-click bookmarklet.

WHY WAS THIS FEATURE REMOVED

I don't know why Microsoft removed this feature. What I do know is it was never perfect and has a number of issues in SharePoint 2007 and 2010. Some of the most common issues are:

  • • Caching problems
  • • Documents opened in external applications are saved with an unexpected user account
  • • Right after user logs in with a different account, the page content shows information from the previous account and the cookies are not properly cleared

In other words, this feature was never meant as a security mechanism. Therefore, even though it's possible to bring the menu option back, you should carefully consider whether doing so is really necessary. After all, it was removed for a reason.

If you want to bring the menu option back for all users, you can modify the Welcome.ascx file in the 15-hive on each server by following Nick Grattan's blog post. If you just want to be able to log in with a different account without this menu option, read on.

HOW TO SIGN IN AS A DIFFERENT USER

Developers and/or IT administrators, myself included, often have to log in with a different user account to test their solutions or customizations, or get a higher-level permissions in a SharePoint site. Even though the menu option is missing, there are several workarounds that can be used to log in as a different user in SharePoint 2013.

Method 1: Internet Explorer's Different User Option

The most common way to sign in as a different user is with Internet Explorer's "Run as different user" option. Just right-click the IE icon while holding the shift key down and click on "Run as different user." Once logged in, just navigate to the SharePoint site. This method is quite cumbersome but it does allow you to run multiple instances of IE and be logged in as a different user in each one.

Note for the Windows 7 or 8 users: if you have IE pinned to your taskbar, holding the shift key and right-clicking on the taskbar icon won't work. You have to right-click the IE icon in the taskbar first, then hold the shift key and right-click on the Internet Explorer option.

Method 2: Navigate to the Close Connection Page

A slightly faster way to accomplish this is to navigate to the Close Connection page. Just visit the following URL in your browser:

http://<site URL>/_layouts/closeConnection.aspx?loginasanotheruser=true

As soon as you hit this page, the familiar pop-up will prompt you for the username to log in with. Once you log in, you will be redirected to the home page.

BOOKMARKLET TO SIGN IN AS A DIFFERENT USER

Bookmarklet (bookmark + applet) is a web browser bookmark that contains JavaScript commands in the URL. This means we can build a bookmarklet that uses JavaScript Object Model in SharePoint 2013 to automate the second method above.

First, let's build the script which uses SharePoint client context to redirect the user to the URL specified above:

  1. if (typeof SP !== 'undefined') {
  2.     var ctx = new SP.ClientContext.get_current();
  3.     var site = ctx.get_site();
  4.     ctx.load(site, 'Url');
  5.     ctx.executeQueryAsync(Function.createDelegate(this, function(sender, args) {
  6.         var url = site.get_url();
  7.         window.location = url + '/_layouts/closeConnection.aspx?loginasanotheruser=true';
  8.     }), Function.createDelegate(this, function (sender, args) {
  9.         alert('Error: ' + args.get_message());
  10.     }));
  11. } else {
  12.     alert('Error: This is not a SharePoint 2010 or 2013 website');
  13. }

Basically, what we are doing is getting the client context of the current SharePoint site, loading the "Url" property of the "site" object via an AJAX request, and then redirecting the browser to the Close Connection page. If we fail to load the "site" object, we display the error. We also display an error if "SP" is undefined, which means that you are not on a SharePoint 2010 or 2013 website.

This script can be tested in the Console window of your browser's development tools. Now we need to add this script to a hyperlink that can serve as a bookmarklet. To do so, just create an HTML file and add the following text to it, which includes the script above without line breaks:

  1. <a href="javascript: (function(){if (typeof SP !== 'undefined') { var ctx = new SP.ClientContext.get_current(); var site = ctx.get_site(); ctx.load(site, 'Url'); ctx.executeQueryAsync(Function.createDelegate(this, function (sender, args) { var url = site.get_url(); window.location = url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'; }), Function.createDelegate(this, function (sender, args) { alert('Error: ' + args.get_message()); })); } else { alert('Error: This is not a SharePoint 2010 or 2013 website'); }})();">SP Login</a>

Open this HTML file in your favorite browser, and drag and drop this link to your bookmarks/favorites bar. Alternatively, you can just create a new bookmark in your browser, call it "SP Login" (or whatever else you like) and use the content of the "href" property of the hyperlink above in place of its URL. Unfortunately, some technical limitations are preventing me from adding this bookmarklet directly to this post.

Incidentally, this bookmarklet can also be used to log in as a different user in SharePoint 2010, since it also exposes the JavaScript Object Model. This can be useful in some scenarios, for example if you have a staging environment for your public site where the ribbon controls are only shown to the "admin" accounts, which are different from your main AD account you use in your organization.

How to Sign in as a Different User in SharePoint 2013的更多相关文章

  1. SharePoint 2013 启用 以其他用户身份登陆(Sign in as different user)

    习惯于SharePoint 2010的用户会发现,SharePoint 2013默认把  以其他用户身份登陆(Sign in as different user)的选项去掉了,这对于开发人员来说很麻烦 ...

  2. Sharepoint2013切换用户菜单

          Sharepoint2013中没有切换用户的菜单,每次登录后,浏览器就会记住密码.要重新换一个用户登录的时候,就需要把浏览器都关闭,然后重新启动.这样非常不方便.特别是在测试权限这一块的时 ...

  3. Integrating SharePoint 2013 with ADFS and Shibboleth

    Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...

  4. 关于如何在Android、Java等非微软平台上建立高信任的SharePoint应用程序

    关于如何在非微软平台上建立高信任的SharePoint应用程序 原文 :http://blogs.msdn.com/b/kaevans/archive/2014/07/14/high-trust-sh ...

  5. SharePoint 2013 一些小技巧

    一.添加“SharePoint 2013 切换用户”标签 相比SharePoint 2010,SharePoint2013版本去掉了切换用户登陆的功能(如下图),其实这个可以通过改welcome.as ...

  6. Sharepoint-Hosted App in 2013资料

    一个完整的流程,可参考网址 My First Sharepoint-Hosted App in 2013 部署第一个APP会遇到各种问题,可以参考网址 App development in Share ...

  7. SharePoint安全 - 在Goolge和Bing中查找SharePoint相关内容

    博客地址 http://blog.csdn.net/foxdave 本篇提供两个查询串字典,分别对应Google和Bing的搜索,用来查询SharePoint网站的相关内容 Google ShareP ...

  8. 【FBA】SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用

    //http://www.cnblogs.com/OceanEyes/p/custom-provider-in-sharepoint-2013-fba-authentication.html 由于项目 ...

  9. [FBA]SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用

    //http://tech.ddvip.com/2014-05/1401197453210723.html 由于项目的需要,登录SharePoint Application的用户将从一个统一平台中获取 ...

随机推荐

  1. RabbitMQ消息交换模式简介

    RabbitMQ是AMQP的一个典型实现,它消息发布者的消息发布到Exchange上,同时需要制定routingkey,可以通过指定交换机的不同模式实现不同的行为. RabbitMQ提供了四种Exch ...

  2. STM32 Timer : Base Timer, Input Capture, PWM, Output Compare

    http://www.cs.indiana.edu/~geobrown/book.pdf An example of a basic timer is illustrated in Figure 10 ...

  3. STM32定时器级联 -- AN2592

    Master configuration When a timer is selected as a master timer, the corresponding trigger output si ...

  4. java 输入一个字符串,打印出该字符串中字符的所有排列

    import java.util.Scanner; public class Demo001 { public static void main(String[] args) { String str ...

  5. .NET轻量级ORM组件Dapper葵花宝典

    一.摘要 为什么取名叫<葵花宝典>? 从行走江湖的世界角度来讲您可以理解为一本"武功秘籍",站在我们IT编程的世界角度应该叫"开发宝典". 如果您在 ...

  6. DevExpress VCL for Delphi 各版本收集下载

    更多VCL组件请到:http://maxwoods.400gb.com/u/758954/1974711 DevExpress VCL 5.7:http://www.ctdisk.com/file/7 ...

  7. 为什要使用预编译SQL?(转)

    本文转自https://www.cnblogs.com/zouqin/p/5314827.html 今天在研发部技术大牛的指点下,我终于明白了为什么要使用SQL预编译的形式执行数据库JDBC:

  8. String转Date的类型转换器

    import org.apache.commons.beanutils.Converter; import org.apache.commons.lang.StringUtils; /* * 定义转换 ...

  9. Unity 动画知识之一

    Unity现在已经用的很广泛啦,可是却一直没有什么美术向的教程. 程序用方面的内容在各个论坛都有讨论,但是美术似乎很弱势啊. 明明美术也很需要掌握引擎方面的内容嘛! 山谷里的野百合还有春天呢 我们美术 ...

  10. SharePoint 2016 工作流报错“未安装应用程序管理共享服务代理”

    前言 最近为SharePoint 2016环境,配置了状态机工作流,然后,用spd创建的时候可以保存,但是发布的时候报错,经过排查解决了问题,记录一下. 报错截图 下面是SharePoint Desi ...