troubleshooting Question

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

Avatar of Shepwedd
Shepwedd asked on
.NET ProgrammingASP.NETC#
11 Comments1 Solution1204 ViewsLast Modified:
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();
    }
}
ASKER CERTIFIED SOLUTION
wolfman007

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros