This is an old thread, but the bug has resurfaced. My tests are showing
that the bug is only fixed if the remote object is server-activated. The
Thread.CurrentPrincipal is still being lost if the remote object is
configured to be client-activated. Has anyone experienced the same thing?

Thanks,
Paul

On Thu, 15 Nov 2001 12:05:06 -0800, Jonathan Hawkins <[EMAIL PROTECTED]>
wrote:

>Wenbin, this issue has been corrected post beta2.
>
>-jhawk
>
>-----Original Message-----
>From: Wenbin Zhang [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, November 15, 2001 11:33 AM
>To: [EMAIL PROTECTED]
>Subject: [DOTNET] Thread.CurrentPrincipal lost after making a call to a
>remote object?
>
>Question:
>  It seems that Thread.CurrentPrincipal object assigned
>  to CurrentThread is lost after making a remote call to an
>  object hosted by another process.  Is this behavior by
>  design, or it is a bug (I am using Beta2 bits)?
>  If the behavior is by design, how to understand this??
>
>I have included some sample code below:
>In my sample Client code below, the GenericPrincipal
>object assigned to the CurrentThread object is LOST
>after making a call to the remote object in the
>"Server.exe" process.
>
>Client.cs: (Compile: csc /debug+ /r:Server.exe Client.cs)
>-------------------------------------------------------------------
>using System;
>using System.Threading;
>using System.Security.Principal;
>using System.Runtime.Remoting;
>using System.Runtime.Remoting.Channels;
>using System.Runtime.Remoting.Channels.Http;
>using System.Runtime.Remoting.Channels.Tcp;
>using System.Runtime.Remoting.Activation;
>
>using TestRemotingNS;
>
>public class RemotingClient
>{
>    public static void Main()
>    {
>        string[] roles = {"GBB", "AP"};
>        IIdentity alice = new GenericIdentity("alice");
>        Thread.CurrentPrincipal = new GenericPrincipal(alice, roles);
>
>        ChannelServices.RegisterChannel(new TcpChannel());
>        object[] activationAttributes =
>                {new
>UrlAttribute("tcp://localhost:4242/MyTestService")};
>
>        IPrincipal prin = Thread.CurrentPrincipal;
>        string userInfo = "\"" + prin.Identity.Name
>                        + "\" is in role \"AP\"?"
>                        + prin.IsInRole("AP");
>        Console.WriteLine("OSThreadId={0}, CLRThread={1}: {2}",
>                       AppDomain.GetCurrentThreadId(),
>                       Thread.CurrentThread.GetHashCode(), userInfo);
>
>        // Making an object activation call to a remote server.
>        ObjectHandle oh = Activator.CreateInstance("Server",
>                                            "TestRemotingNS.TestServer",
>                                            activationAttributes);
>
>
>        prin = Thread.CurrentPrincipal;
>        userInfo = "\"" + prin.Identity.Name + "\" is in role \"AP\"? "
>                 + prin.IsInRole("AP");
>        Console.WriteLine("OSThreadId={0}, CLRThread={1}: {2}",
>                        AppDomain.GetCurrentThreadId(),
>                        Thread.CurrentThread.GetHashCode(), userInfo);
>    }
>}
>
>Server.cs: (Compile: csc /debug+ Server.cs)
>----------------------------------------------------------------
>using System;
>using System.Threading;
>using System.Runtime.Remoting;
>using System.Runtime.Remoting.Channels;
>using System.Runtime.Remoting.Channels.Http;
>using System.Runtime.Remoting.Channels.Tcp;
>
>namespace TestRemotingNS
>{
>  public class TestServer : MarshalByRefObject
>  {
>    public string GetInfo()
>    {
>        string info = "OSThreadId=" + AppDomain.GetCurrentThreadId()
>                + ", CLRThread=" + Thread.CurrentThread.GetHashCode();
>        return info;
>    }
>  }
>
>  public class RemotingHost
>  {
>    static void Main(string[] args)
>    {
>      RemotingConfiguration.ApplicationName = "MyTestService";
>
>      ActivatedServiceTypeEntry ASTE =
>         new
>ActivatedServiceTypeEntry(typeof(TestRemotingNS.TestServer));
>
>      RemotingConfiguration.RegisterActivatedServiceType(ASTE);
>
>      ChannelServices.RegisterChannel(new TcpChannel(4242));
>      Console.ReadLine();
>    }
>  }
>}
>
>Thanks a lot,
>
>Wenbin Zhang
>OneSource Information Services, Inc.
>300 Baker Avenue
>Concord, MA 01742
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET,
>or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

This is an old thread, but the bug has resurfaced. My tests are showing
that the bug is only fixed if the remote object is server-activated. The
Thread.CurrentPrincipal is still being lost if the remote object is
configured to be client-activated. Can anyone

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to