locked
Loggin in as a different user RRS feed

  • Question

  • Hello ,

    I want a link that the users can click which supports logging in as a different user and then redirects them back to the same page.The issue is the page currently the user is on is also a layouts page .So the below code will work but take the user to the home page not the layouts page they are currently on which is

    http://test.net/_layouts/15/EditProfile.aspx

    function ChangeLogin()
    {
        var url = window.location.host;
        alert(url);
        var loginurl ="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'
       
          location.href = loginurl;

    }

    Thanks

    Thursday, March 6, 2014 5:34 PM

Answers

  • Hi SharePoint99,

    You can add Source parameter to the url, it will redirect to your respected url.

    In your code sample, first get the current page url, set it as SourceUrl.

    var loginurl ="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'+‘Source=’+SourceUrl.

    Thanks,

    Qiao

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Qiao Wei
    TechNet Community Support

    • Proposed as answer by Ilqar Alizade Monday, March 10, 2014 9:45 AM
    • Marked as answer by Qiao Wei Monday, March 17, 2014 3:02 AM
    Monday, March 10, 2014 8:20 AM

All replies

  • To work around this issue, use one of the following methods.

    • Start Windows Internet Explorer by using the Run as different user option, and then go to the SharePoint site
    • Access the SharePoint site by using the following URL:
      http://<site url>/_layouts/closeConnection.aspx?loginasanotheruser=true

      2013-04-10-MaintenancePages-0a1.png

      Locate and then open the following file in a text editor: 
      C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx ( use always a copy ).

      2013-04-10-MaintenancePages-02.png

      Add the following element before the existing "ID_RequestAccess" element:


      <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"  
      Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"   
      Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"   
      MenuGroupId="100"   Sequence="100"   UseShortId="true"   />
      

      2013-04-10-MaintenancePages-03.png

      Save the file.


    Sugumaran Srinuvasan

    Thursday, March 6, 2014 7:37 PM
  • Thanks for replying but I don't need this solution..I need that one link to work.
    Thursday, March 6, 2014 8:18 PM
  • Hi SharePoint99,

    You can add Source parameter to the url, it will redirect to your respected url.

    In your code sample, first get the current page url, set it as SourceUrl.

    var loginurl ="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'+‘Source=’+SourceUrl.

    Thanks,

    Qiao

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Qiao Wei
    TechNet Community Support

    • Proposed as answer by Ilqar Alizade Monday, March 10, 2014 9:45 AM
    • Marked as answer by Qiao Wei Monday, March 17, 2014 3:02 AM
    Monday, March 10, 2014 8:20 AM
  • Hi,

    This works now . thanks a lot. The Problem was, loginURL="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'; when I gave the credentials It was being redirected to root site. but I didn't have the access for the root site so i got access denied error. 

    Now the problem was solved. using your reference added the SourceUrl along with loginURL  loginurl ="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'+‘Source=’+url +.


    • Edited by KaruKarthi Thursday, September 10, 2015 10:42 AM
    • Proposed as answer by KaruKarthi Thursday, September 10, 2015 10:42 AM
    Thursday, September 10, 2015 10:41 AM
  • Hi, I have used the above link but I am prompted to enter credentials multiple times and my web app is added in the Trusted sites.

    Please help.


    SharePoint Developer and Administrator

    Wednesday, February 22, 2017 9:48 PM
  • Thank you for the clue!

    I have been trying for the last 2 days to figure out this "sign in as different user" option in the custom access denied page in SP2013 & SP2016 farm. Every time it was redirecting to the root site collection. Now this issue is solved and "sign in as different user" button is working as expected.

    Hope, this will help someone - 

    <script type="text/javascript">
    $(function BindFunctionToButtonClick() {
    $('#btnCloseConnection').on('click', function (e) {
    e.preventDefault();

    var $currentWebUrl = _spPageContextInfo.webServerRelativeUrl; 
    var $signInUrl = "/_layouts/15/closeConnection.aspx?loginasanotheruser=true";

    var $navigateUrl = $currentWebUrl + $signInUrl + "&Source=" + $currentWebUrl;
    window.location.replace($navigateUrl);
    });
    });
    </script>


    Wednesday, April 4, 2018 8:26 PM
  • Any luck on multiple times prompt for credentials? Its asking me two times of the same user account is used. If I use that url (closeconnection.aspx) directly in browser (without having log in earlier ), it asks me three time.

    I am basically trying to make people explicitly login if they want to access a specific page (even they are already login or not and even if SSO is on). I am trying to utilize closeconnection.aspx or accessdenied.aspx. But same result - multiple prompts. after entering credentials 2 (if already loged in ) or 3 (if new session) times, I am getting on site. So its not about correct credentials.

     

    MOSS programmer

    Tuesday, May 22, 2018 5:37 PM