Login as different user

Hi everybody,

My request out here is Urgent, though i have passed through what I could access in this forum and others also, but cannot finding a working solution.

I have designed an ASP.NET application, at our organizational intranet, I have used Windows Authentication and it worked very efficiently. My problem is, I want my application to ask for re-entering of employee's credential when he clicked on a log out control ( it could be anything - i didn't decided what will trigger log out yet ). I want it to be like Sharepoint page where you can log as another user in the same machine.

I m using following code but not working properly.

[CODE]
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
_User = User.Identity.Name.Replace("Domain\", "");
Label1.Text = _User;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{

Response.StatusCode = 401;
Response.StatusDescription = "Unauthorized";
Response.End();
Response.Redirect("Default.aspx");
}
[/CODE]
and my HTML or aspx CODE IS
[CODE]

Untitled Page



Hello

Sign in as Different user




[/CODE]
I am waiting ...

Thanks.

Comments

  • I have also tried
    [CODE]
    document.execCommand("ClearAuthenticationCache")
    [/CODE]
    but it only works on IE and on the server machine only , on clients machine it won't work
  • I found the following code working partially
    [CODE]
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!this.IsPostBack)
    {
    this.hiddenCurrentUser.Value = Request.LogonUserIdentity.Name;
    _User = User.Identity.Name.Replace("Domain\", "");
    Label1.Text = _User;
    }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    if (this.hiddenCurrentUser.Value != Request.LogonUserIdentity.Name)
    {
    Response.Redirect("Default.aspx");
    }
    else
    {
    Response.StatusCode = 401;
    Response.StatusDescription = "Unauthorized";
    Response.End();
    }

    }
    [/CODE]
    and HTML is
    [CODE]

    Untitled Page



    Hello

    Sign in as Different user





    [/CODE]

    now the problem is

    what happen if i enter the same credential again?

    i am using the above given code and when i am entering different credentials then its working fine.

    but when i am using same credentials then it again ask for credentials for 2 more times.

    and after clicking 3 times the page get washout.

    and when i click on back button and again refresh the page then it accepts the credentials...



    plz suggest me some way to overcome this problem
  • If you want a "cross browser" (tested in IE5, IE6, IE7, IE8, FireFox 3.5.5 and Google Chrome 3) "sign in as different user" button, you might want to read mine blog post at:
    http://www.roelvanlisdonk.nl/asp-net-c-how-to-sign-in-as-different-user-like-in-microsoft-sharepoint-with-windows-authentication
    It explains you will have to send a 401 response:

    ///
    /// Send a 401 response
    ///
    public void Send401()
    {
    // Create a 401 response, the browser will show the log-in dialogbox, asking the user to supply new credentials,
    // if browser is not set to "automaticaly sign in with current credentials"
    Response.Buffer = true;
    Response.StatusCode = 401;
    Response.StatusDescription = "Unauthorized";

    // A authentication header must be supplied. This header can be changed to Negotiate when using keberos authentication
    Response.AddHeader("WWW-Authenticate", "NTLM");

    // Send the 401 response
    Response.End();
    }

    Two 401 responses must be send when the browser is set to "automaticaly sign in with current credentials"

    By looking at the MSIL code of the Microsoft.SharePoint.ApplicationPages.dll, I guess this is the way Microsoft Sharepoint does it, using the _layoutsAccessDenied.aspx




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories