Custom Identity

Custom Identity

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


webjedi posted on Monday, November 12, 2007

Hi.

I'm following the PTTracker model of Identities, I'm trying to add an Integer property called adminID to the identitiy to use in my code behind of my page.  I've added it to my Fetch method and have made (what I think) are the appropriate changes to the business methods (declaration and property).

However in my app I cannot access it using User.Identity.adminID like I can User.Identity.Name....is there something I need to do in my membershipprovider?

Ryan

JoeFallon1 replied on Monday, November 12, 2007

The Interface only exposes certain values.

Try casting User.Identity to your specific type.

Then you should be able to see your custom properties.

Joe

 

webjedi replied on Monday, November 12, 2007

I think there is something more to this....trying to cast I get an error:

Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'CslaProject.Library.AdminSecurity.AdminIdentity'.

Something seems off...like my AdminPrincipal class needs to do something else...

Ryan

webjedi replied on Monday, November 12, 2007

Got it...

Here's the thread that sent me down the right road

http://forums.lhotka.net/forums/thread/15308.aspx

webjedi replied on Monday, November 12, 2007

Ok so this works but now in order to make it globally available is it ok to make this a public property of my Master Page and then access the property from my pages?

 

RockfordLhotka replied on Monday, November 12, 2007

Yes, though I usually do it with a static class or Module in my business layer:

public static class Security
{
  public static MyPrincipal User()
  {
    return (MyPrincipal)Csla.ApplicationContext.User;
  }
}

Then you can use Security.User anywhere in your app and you always get the right type automatically.

webjedi replied on Tuesday, November 13, 2007

Perfect!

Copyright (c) Marimer LLC