Print Page | Close Window

Anytime I use the persistancemanager, it seems to overwrite Thread.CurrentPrincipal

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=274
Printed Date: 14-Oct-2025 at 8:21am


Topic: Anytime I use the persistancemanager, it seems to overwrite Thread.CurrentPrincipal
Posted By: Customer
Subject: Anytime I use the persistancemanager, it seems to overwrite Thread.CurrentPrincipal
Date Posted: 16-Jul-2007 at 11:48am
Anytime I use the persistancemanager, it seems to overwrite Thread.CurrentPrincipal. I am sure it's some simple setting that I need to set. Please advise. 

Here is a sample code I am using.

MessageBox.show(System.Threading.Thread.CurrentPrincipal.Identity.Name);

PersistenceManager pm = PersistenceManager.DefaultManager;

Student student = pm.GetEntity<Student>(new PrimaryKey(typeof(Student), new Guid("e6584153-45d5-4371-8d4f-15a9e0d7f3e1")));

MessageBox.show(System.Threading.Thread.CurrentPrincipal.Identity.Name);

The two Message boxes give me following results

1) user1  (this is authenticated user's id so it's correct)

2) DefaultPrincipal - 0  (PM seems to over-write and therefore I lose my principal).




Replies:
Posted By: IdeaBlade
Date Posted: 16-Jul-2007 at 11:51am

This is intentional.

 

Creating a new PersistenceManager always causes a principal to be assigned to the currently running thread.

 

The intent is that each DevForce application begins with a login during which the LoginManager computes a principal that is assigned to the currently running thread.  The principal is determined securely by code that runs on the server.  If you do not implement a LoginManager, the null principal is assigned.

 

If you do not wish for this behavior, save the value of the principal before creating a PersistenceManager.  Then, after the value of the principal is overwritten, restore the value.




Print Page | Close Window