none
Update custom principal in SetThreadPrincipal(principal) RRS feed

  • Question

  • Hi

    If any way is available for update the prinicipal in appdomain level

    System.AppDomain.CurrentDomain.SetThreadPrincipal(principal);

    Note : I don't want -->Thread.currentPrinicipal =prinicipal

    Advance Thanks

    Arun

    Monday, October 22, 2012 5:56 AM

Answers

  • I don't think you understand what the principal means.  The principal is the owner of the object.  why would you want to change the owner of an object every 5 minutes?  I think you want to refresh an object that is assciated with the thread.  A thread is a process so the owner is another process.  You can't set the thread owner while it is running.

    jdweng

    Monday, October 22, 2012 6:07 PM
  • @Joel,

    Are you sure the Thread.CurrentPrincipal is supposed to be another process. That just sounds silly. The documentation states that the property is used in role based security.

    @Arunkumar,

    http://msdn.microsoft.com/en-us/library/vstudio/system.appdomain.setthreadprincipal(v=vs.100).aspx

    The example on this page pretty much shows what the method does. After you use the method, every new thread will have the principal attached. As far as I can see, already running threads are not affected. What is not working for you when you use SetThreadPrincipal? All I can determine from your question is that your previous implementation did not work.

    Monday, October 22, 2012 7:28 PM
  • Read what I said.  A thread is a process.  The parent of a thread is another process.  The principle is the owner (not parent) which is a user.  I wish the Task Manager would show both the PID (Porcess ID) and the PPID (Parent Process) ID like in Unix.  You would then see three important columns in th etask manager

    1) PID  - This is the Process

    2) Owner   - This is the priciple which is the user account

    3) PPID - This is the Parent of the Process.

    When you create a thread the PPID is the program that launched the thread.  The PID is the thread.  The Owner (or Principle) is the User Account that created the process.

    Why would you want to refresh the the PID, the PPID, or the Owner of a thread.  You normally want to refresh an object!


    jdweng

    Monday, October 22, 2012 9:43 PM

All replies

  • Are you asking to set the User to a differenet user?  The webpage below is the documentation for the class with an example explain how to set the principla to the current principlal.  To set the user to a different user you would need admin priviledges.

    http://msdn.microsoft.com/en-us/library/system.appdomain.setthreadprincipal.aspx


    jdweng

    Monday, October 22, 2012 7:13 AM
  • Hi

    Thanks for your quick reply

    Current Implementation:

    I have a custom prinicipal and set into the app domain level using the following code

    System.AppDomain.CurrentDomain.SetThreadPrincipal(principal);

    Previous Implemenation:

    Thread.CurrentPrincipal=principal;

    Exception:

    In touch monitor while click any link Thread.CurrentPrincipal become null

    Expectation:

    Every five minutes i need to update the principal in appdomain but i couldn't due to the below execption

    Default principal cannot be set twice.

    Monday, October 22, 2012 5:22 PM
  • I don't think you understand what the principal means.  The principal is the owner of the object.  why would you want to change the owner of an object every 5 minutes?  I think you want to refresh an object that is assciated with the thread.  A thread is a process so the owner is another process.  You can't set the thread owner while it is running.

    jdweng

    Monday, October 22, 2012 6:07 PM
  • @Joel,

    Are you sure the Thread.CurrentPrincipal is supposed to be another process. That just sounds silly. The documentation states that the property is used in role based security.

    @Arunkumar,

    http://msdn.microsoft.com/en-us/library/vstudio/system.appdomain.setthreadprincipal(v=vs.100).aspx

    The example on this page pretty much shows what the method does. After you use the method, every new thread will have the principal attached. As far as I can see, already running threads are not affected. What is not working for you when you use SetThreadPrincipal? All I can determine from your question is that your previous implementation did not work.

    Monday, October 22, 2012 7:28 PM
  • Read what I said.  A thread is a process.  The parent of a thread is another process.  The principle is the owner (not parent) which is a user.  I wish the Task Manager would show both the PID (Porcess ID) and the PPID (Parent Process) ID like in Unix.  You would then see three important columns in th etask manager

    1) PID  - This is the Process

    2) Owner   - This is the priciple which is the user account

    3) PPID - This is the Parent of the Process.

    When you create a thread the PPID is the program that launched the thread.  The PID is the thread.  The Owner (or Principle) is the User Account that created the process.

    Why would you want to refresh the the PID, the PPID, or the Owner of a thread.  You normally want to refresh an object!


    jdweng

    Monday, October 22, 2012 9:43 PM
  • @Joel,

    This makes more sense. Your previous message states: "A thread is a process so the owner is another process.  You can't set the thread owner while it is running.". I think you might have switched owner and parent around on that one. I get you now, and you are absolutely right about parent and owner of a PROCESS. Also a thread is not a process, but that is a discussion for another time.

    However the principal of a THREAD might be a Windows User, but it can actually be any implementation of IPrincipal that you can construct and put in there.



    • Edited by Jeroen Vos Tuesday, October 23, 2012 6:19 AM
    Tuesday, October 23, 2012 5:41 AM