Web form thread casting error

Web form thread casting error

Old forum URL: forums.lhotka.net/forums/t/3215.aspx


CMoreno posted on Tuesday, July 17, 2007

We just started creating our web interface using the CSLA framework. Because our windows application gets the UserID out of the windows thread, we are having the following casting exemption: Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'XE700.Library.Security.XEIdentity'.

Line: int CurrentUserLevel = ((XEIdentity)Thread.CurrentPrincipal.Identity).UserLevel;

On XE700\XE700.Library\XEBusinessListBase.cs   

How can we go around this? I will appreciate any feedback

Thanks

 

 

RockfordLhotka replied on Tuesday, July 17, 2007

If you are using Windows authentication then you should be using a WindowsIdentity, not a custom identity.

If you are using a custom identity then you need to set the current principal on every page request (in global.asax). See Chapter 10 for details.

If you are trying to do both, then you still need to set the current principal on every page request, you'll just pull the username from the WindowsIdentity when creating your custom principal.

In any case, I recommend you use Csla.ApplicationContext.User rather than directly interacting with either HttpContext.Current.User or System.Threading.Thread.CurrentPrincipal, because (as discussed in the book) ApplicationContext.User addresses some scenarios where either of those other two locations may be incorrect at times.

Copyright (c) Marimer LLC