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.

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");       
    }

and my HTML or aspx CODE IS

<head runat="server">
    <title>Untitled Page</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>
    </div>
    </form>
</body>
</html>

I am waiting ...

Thanks.

I Have also tried

document.execCommand("ClearAuthenticationCache")

but it only works on IE and on the server machine only , on clients machine it won't work

I Have also tried

document.execCommand("ClearAuthenticationCache")

but it only works on IE and on the server machine only , on clients machine it won't work

somewhere i found this modified 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();
}
           
    }

and HTMl Code is

<head runat="server">
    <title>Untitled Page</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>
    </div>
<input type="hidden" id="hiddenCurrentUser" name="hiddenCurrentUser" runat="server" value="0" visible="false" />
    </form>
</body>
</html>

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..

Be a part of the DaniWeb community

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