I am trying to implement the functionality for "Sign in as different user" link button on my custom access denied page in sharepoint 2010 using the below code

string site = base.Web.ServerRelativeUrl.ToString();
Response.Redirect("~/" + site + "/_layouts/closeConnectionNew.aspx?loginasanotheruser=true");

but it is not working. I also tried calling the javascript funtion with the following code but of no use. What am I missing?

string site = base.Web.ServerRelativeUrl.ToString();
 string urlforsign = "~/" + site + "/_layouts/closeConnectionNew.aspx?loginasanotheruser=true";
urlforsign = urlforsign.Replace("/", "\u002f");
 Response.Redirect("javascript:LoginAsAnother('" + urlforsign + "', 1)");
  • Your url seems incorrent. It should be "_layouts/closeConnection.aspx?loginasanotheruser=true" Jun 24, 2016 at 10:14
  • @VishalM.Patil I made a copy of closeConnection.aspx so that I could modify it if required
    – Tarun K
    Jun 24, 2016 at 10:16
  • It is not working with closeConnection.aspx as well.
    – Tarun K
    Jun 24, 2016 at 11:53
  • Remove "~/" and Get site url as string site = SPWeb.Url.ToString(); and try. Jun 24, 2016 at 12:13
  • @VishalM.Patil tried replacing"~/" with string site = SPWeb.Url.ToString();, but it did not work.
    – Tarun K
    Jun 30, 2016 at 14:16

1 Answer 1


Try this, it's working:

weburl + "/_layouts/closeConnection.aspx?loginasanotheruser=true"
  • not working using the weburl also
    – Tarun K
    Jun 27, 2016 at 14:25
  • There is also one change here from your code. Here 'closeConnection.aspx' and not 'closeConnectionNew.aspx' ,. so try with that .. Jun 28, 2016 at 4:07
  • Please note that closeConnection.aspx is a copy of closeConnection.aspx. I had already tried the code with closeConnection.aspx. Since I have created the custom access denied page, hence I decide to copy the closeConnection.aspx and perform any chenges in the copy if required
    – Tarun K
    Jun 29, 2016 at 9:40
  • I redirects to the correct path i.e. "siteName/_layouts/accessdenied.aspx?loginasanotheruser=true" as mentioned in closeConnection.aspx but no prompt shows up for the user to enter credentials
    – Tarun K
    Jun 29, 2016 at 10:05

Your Answer

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

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