CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Unable to cast object of type 'System.Security.Principal.GenericIdentity' ...

rated by 0 users
This post has 3 Replies | 3 Followers

Top 25 Contributor
Posts 450
Tiago Freitas Leal Posted: Sun, Mar 25 2012 9:41 PM

On my Web project I get this message when I'm not logged on.

System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'Project.Business.Security.CustomIdentity'.

This won't happen in production as users can't do anything at all until they login.

Strange enough, this doesn't happen when I fetch data, only when I try to update data.

Tiago Freitas Leal, CslaGenFork (Open Source CSLA code generator)

Not Ranked
Posts 14
Kevin replied on Tue, Nov 27 2012 3:46 AM

Hi,

is there any solution for this problem? I have the same problem.

EDIT:

I have a CustomIdentity where I set the AuthenticationType to Custom. In my App.config (Client) I'll have this <add key="CslaAuthentication" value="Custom"/> and in my server config I'll have this <add key="CslaAuthentication" value="Custom"/>.

I use a CustomProxy which is also in the AppSettings section. Fetching data works, but no update. I saw in my CustomProxy, the DataPortalContext Principal is null. That's not right, or?

My CustomPrincipal und my CustomIdentity are both serializable.

[Serializable]

public class CustomPrincipal : Csla.Security.CslaPrincipal

-------

[Serializable]

public class CustomIdentity : CslaIdentityBase<CustomIdentity>

Kind regards

Kevin

Top 10 Contributor
Posts 9,270

Are you using the ASP.NET Development Web Server? That server (code-named Cassini) has well-known limitations that block the use of custom principal types.

Use IIS Express instead, as it is more robust overall, and doesn't have the same limitations as Cassini.

Rocky

Not Ranked
Posts 14
Kevin replied on Thu, Nov 29 2012 7:59 AM

I'm using a WPF Application and WCF Services (with the DataPortalHost approach).

In my custom Proxy class I figured out, that the IsServerRemote property was false during GetProxy call from CSLA. So I set it to true in the GetProxy Method (_isServerRemote = true;) and than I'will have a valid Principal in the DataPortalContext. But in my ApplicationContext after logging in to my application, the Csla.ApplicationContext user was not authorized. So at least I changed the CustomProxy Update Method to this:

return GetProxy(obj.GetType()).Update(obj, new Csla.Server.DataPortalContext(Csla.ApplicationContext.User, true));

I'm using the CustomProxy for 3 different things: Local usage (return LocalProxy), WCF Server A and WCF Server B, because some business objects need another wcf service url (Server B) to store data.

This will work, but I don't know if this is the best way to do that.

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems