Ultimate Collection - { fslWeb & faisalmb.com } Ultimate Collection - { fslWeb & faisalmb.com }   
Home   |   Site   |   Posts (389)   |   Tags Xplorer   |   Feed SubscribeFree! Aha! you surfing post Sigin as different user i...    Partner Site - Real Home Contact Search   

Wed

20

Apr

2011

Tue-14-02-2012
Likes 1    Dislikes 1
   

Sigin as different user in asp.net using Windows authentication

If you want to have signin as different user functionality like sharepoint in your asp.net application, following workaround you might be looking for.
After setting your web.config file's 

<authentication mode="Windows" />

and in IIS after remove anonymous authentication and enable windows authentication, have following code snippet where you want to have this functionality

In your aspx page

    <div>You are logged in as <br /> <%=User.Identity.Name%> <br /><br /> 
    <asp:LinkButton ID="lnkSignOut" runat="server" Text="Sign in as different user" onclick="lnkSignOut_Click"></asp:LinkButton>


In your code behind file

 protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        Session["logOutRequested"] = false; //Initialize value. This will be set to true when user will click on sign in as differnet user
    }
}


protected
void lnkSignOut_Click(object sender, EventArgs e)
{
    if (null != Session["logOutRequested"] && !Convert.ToBoolean(Session["logOutRequested"])) // Check if user is clicking link first time
    {
        Session["logOutRequested"] = true; //Set value that user want to sign in as differnet user
        Response.StatusCode = 401;
        Response.StatusDescription = "Unauthorized";
        Response.End();
    }
    else
    {
        Session["logOutRequested"] = false; //Initialize value again after user is authenticated with differnet or same user again.
    }
}


Hope this workaround will help.

In case if above workaround is not working, you may try following one
www.roelvanlisdonk.nl/?p=825

 

 

 


Comments

Ana  United States | Reply 2/4/2012 4:21:07 PM
Visitor Comment   nice!

Add Comment Add comment

 
 
 
   Country flag

Click to change image  --> 

biuquote
  • Comment
  • Preview
Loading





Intro

Faisal Bashir
Consultant / Software Architect
KalSoft Limited Dubai
Microsoft Certified Technology Specialist.
[more]

Right Now

How could u reach the pearl by only looking at the sea? if u seek the pearl, be a diver: the diver needs several qualities, he must trust his rope and his life to the Friend's hand, he must stop breating and he must jump - Jalaluddin Rumi.

Random Visuals

Recent Comments

Comment RSS

Next Quote ya Allah, when i want to talk to You, i offer Namaz (parayer)
and when i want You to talk to me, i read Quraan.
Previous Quote

1773478 hits. (Best viewed @ 1024x768 resolution min.) Comments here...
© 2001-2013 Muhammad Faisal | Disclaimer | Contact | Partner Site