Set Identity of Thread

后端 未结 3 1858
Happy的楠姐
Happy的楠姐 2020-12-06 16:09

In C#, how do I set the Identity of a Thread?

For example, if I have Thread MyThread, which is already started, can I change MyThread\'s Identity?

Or is this

3条回答
  •  再見小時候
    2020-12-06 16:55

    Update for the accepted answer [apply ONLY on .NET framework 4.5 and above]
    In .NET 4.5 the property IsAuthenticated has no set accessor, so you can not set it directly as the accepted answer doing.
    You can use the following code for setting that property.

    GenericIdentity identity = new GenericIdentity("someuser", "Forms");
    Thread.CurrentPrincipal = new GenericPrincipal(identity, new string[] { "somerole" });
    

提交回复
热议问题