I am having some weird issues with accessing the UserID for the user logged in.
During testing I am getting an error using the following line in a DataPortal_Fetch method.
.Parameters.AddWithValue("@UserID", CType(Csla.User.Identity, Security.SecurityIdentity).ID)
The error is ......Security.SecurityIdentity inherits from ReadOnlyBase and implements iIdentity
The weird part is this line works fine in another BusinessObject. Both of them inherit from BusinessBase. the one difference is the failure happens in the DataPortal_Fetch but in the class where it works is the DataPortal_Insert. Is this the issue? (it is not valid in fetch methods)
Anyone got some ideas? or what code you need to see to help me out.
Thanks,
Mike
Just wanted to add some more information... I was looking through my PDF of the book and can't find any use of Csla.User so I tried the following line...
.Parameters.AddWithValue("@UserID", CType(Csla.ApplicationContext.User.Identity, Security.SecurityIdentity).ID)
and that didn't work either. The same error gets thrown. And I am logged in (oops looks like maybe I am not... will do more testing on this... seems Csla.User.Identity.IsAuthenticated is False right before the line it fails on)
Mike
OK so I am fairly sure I have figured out what the probelm is. It is the fact that this call is in an event that gets raised by a control that does it processing asynchronsly (sp?) so the event is being raised by different threads. Can someone verify this is the issue?
So what is the best way to handle this? Should I store a reference to the user on the main form and use that reference (if I can.. kinda of new on delaing with multiple threads)? Or is there some other way to do it?
Thanks,
Mike
CSLA .NET includes Csla.ApplicationContext.User - that's the only User property in the framework, and is the one I would think you'd be using. If you do have a Csla.User property, it is a customization you or someone on your team must have made.
If you are using custom authentication, which it sounds like you are, you must make sure that the principal object (Csla.ApplicationContext.User) is restored on each page request. Typically this is done in global.asax as shown in Chapter 10 in the book. After that point, Csla.ApplicationContext.User should provide access to the pricipal object in all your code.
Thanks for the reply.
We (me as I am the lone developer using the framework so far) have not modified the CSLA code at all. I think maybe I might have screwed something up with importing the namespace or something?
This is a WinForms app, not webforms.
Mike
Copyright (c) Marimer LLC