Hello,
I have an ASP.NET website that uses Windows Authentication to authenticate users against Active Directory. How can I implement a "Sign-On as Different User" just like SharePoint 2007? Our SharePoint site uses Windows Authentication as well and when you click to "sign-on as a different user" you are prompted with the NT login prompt and then redirected. It would be really nice to know how to do this because I've been looking for several days and can't seem to find any concrete information for Windows Authentication.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.hiddenCurrentUser.Value = Request.LogonUserIdentity.Name; 
            Label1.Text = User.Identity.Name.Replace("DOMAIN\\", ""); ;
        }
    }
    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();
        }

    }

Use the following HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<p>Hello <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Sign in as Different user</asp:LinkButton>
<asp:HiddenField ID="hiddenCurrentUser" runat="server" />
    </form>
</body>
</html>

Reference:
http://forums.asp.net/t/1309377.aspx
http://forums.asp.net/p/1279595/2441063.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.