3

Requirement- There should be a link in a custom access denied page to sign in as a different user in a SP 2013 web application.

This is achieved by creating a custom application page and deployed as a farm solution. Sign in as different user is a hyperlink in the page and linked to URL _layouts/closeConnection.aspx?loginasanotheruser=true. This link works fine when it is deployed as application page in the 15 hive.

However, once I make this the access denied page for my web application, the link redirects back to the access denied page itself.

How do I fix this issue?

1
  • which source parameter should i put to redirect to the current page? you can redirect to the root site home page by using the following parameter http://<site URL>/_layouts/closeConnection.aspx?loginasanotheruser=true Commented Nov 7, 2016 at 12:31

1 Answer 1

2

You have to specify the source parameter in the URL to get redirected to your site. To achieve this, you have two options.

  1. Create a link that will redirect the user to the originating site (the source parameter should be included in the access denied page)

    window.location.href = window.location.href.replace(//_layouts/(\d{2}/)?accessdenied.aspx\?/i, '/_layouts/$1closeconnection.aspx?loginasanotheruser=true&');

  2. Use the SharePoint built-in JavaScript function to login as a different user

    LoginAsAnother('/_layouts/closeConnection.aspx?loginasanotheruser=true',1);

Enclose the above code in a href tag (on the onclick event).

LoginAsAnother(urlToRedirectAfterLogin, useSource[otherwise the source will be the current page])

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.