using System; using System.Security.Principal; using System.Security.Permissions; using System.Threading; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Messaging; using System.Reflection; [assembly: AssemblyKeyFile("mykey.snk")] [assembly: AssemblyVersion("2.1.0.0")] class Starter { static public void Main() { GenericIdentity identity=new GenericIdentity("Generic"); GenericPrincipal principal=new GenericPrincipal(identity, new string[] {"Administrator"}); Thread.CurrentPrincipal=principal; principal=(GenericPrincipal) Thread.CurrentPrincipal; Console.WriteLine("Main: Identity is {0} and he is {1}an administrator", principal.Identity.Name, principal.IsInRole("Administrator")?"":"not "); TcpChannel channel=new TcpChannel(4000); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType( typeof(Server), "TheServer", WellKnownObjectMode.SingleCall); System.Console.WriteLine(" to exit"); System.Console.ReadLine(); } } public class Server : MarshalByRefObject, IServer { public void DoSomething() { ForeignPrincipal fp=(ForeignPrincipal) CallContext.GetData("ClientContext"); Thread.CurrentPrincipal=fp.principal; Console.WriteLine("Doing something for {0}.", Thread.CurrentPrincipal.Identity.Name); Console.WriteLine("Something..."); } }