We help IT Professionals succeed at work.
Get Started

How do I use impersonation in a ASP.NET C# Web Site to simply show the current users login details in a textbox?

Shepwedd
Shepwedd asked
on
1,198 Views
Last Modified: 2013-12-17
I have written the attached code to write the current users login details to a text box control in my asp.net web site but all I seem to get written to the text box as a result is: "System.Security.Principal.WindowsImpersonationContext". It's as if the compiler isn't picking up the class? When I debug I can see that the User.Identity is pulling back the correct details but upon running my text box doesn't reflect these details?

Thanks.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Principal;
using System.Runtime.InteropServices;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Security.Principal.WindowsImpersonationContext impersonationContext;
        impersonationContext =
            ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
 
        TextBox1.Text = impersonationContext.ToString();
 
        //impersonationContext.Undo();
    }
}

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE