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?

  • 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 Nov 7, 2016 at 12:31

1 Answer 1


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


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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.