In ASP.NET you have to deal with three identities (Process, Thread and Managed Identity). In DevelopMentor‘s “Essential .NET Security” course i use this little tool, originally written by Keith, to show these identities.
I updated the code to .NET 2.0. You can see how to “RevertToSelf” using managed code, as well as the new overload in WindowsIdentity.GetCurrent() to figure out if you are currently impersonating.
I included two formats – ASPX and ASMX. The ASMX is especially useful to diagnose double hop scenarios.