New Posts New Posts RSS Feed: User ID from asp.net security
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

User ID from asp.net security

 Post Reply Post Reply
Author
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Topic: User ID from asp.net security
    Posted: 06-Jan-2010 at 8:56am
The name of the assembly in which the CustomLoginManager is defined must be specified in the top-level probe asssembly names, even if it might already be in the probes under an EdmKey.  So if the class is defined in assembly "ServerLib" then the config will look something like this: 
 
<ideablade.configuration version="5.00" ... >
    <probeAssemblyNames>
       <probeAssemblyName name="ServerLib" />
    </probeAssemblyNames>
    ...
</ideablade.configuration>
Back to Top
manishaudio View Drop Down
Newbie
Newbie


Joined: 24-Nov-2009
Posts: 8
Post Options Post Options   Quote manishaudio Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jan-2010 at 7:42am
How do I configure IB to use CustomLoginManager.  I don't understand the documentation.  If you could send me the snippet of the config file, I'd appreciate it.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 05-Jan-2010 at 3:36pm
The UserBase is very IPrincipal and IIdentity oriented, so it holds name and roles and not much else.  The UserBase class is DevForce's IPrincipal implementation for Silverlight, but you can extend it fairly easily to do what you need.  As you mention you will also need to subclass the AspAuthenticatingLoginManager.   Alternatively, and harder, you could write your own ILoginManager and IPrincipal implementations.  Here's a sample of what you can do to stick the UserID into the custom UserBase so that it's available on the Silverlight client, as well as any server-side DevForce code your write.
 
// In CustomUser.cs in a server project, and shared in an SL project:
[DataContract]
public class CustomUser : UserBase, IKnownType {
   public CustomUser(IIdentity identity, IEnumerable<string> roles) :
      base(identity, roles) { }
 
   [DataMember]
   public Guid UserID { get; set; }
}
 
// In CustomLoginManager.cs in a server project:
public class CustomLoginManager : AspAuthenticatingLoginManager {
   protected override IPrincipal CreateUserCore(string name, bool isAuthenticated, IEnumerable<string> roles) {
      var user = base.CreateUserCore(name, isAuthenticated, roles) as CustomUser;
      user.UserID = (Guid)Membership.GetUser(name).ProviderUserKey;
      return user;
   }
}
 
Before this week we actually hadn't had any requests for the UserID.  We will look at incorporating this so that you don't need to write custom code.
Back to Top
manishaudio View Drop Down
Newbie
Newbie


Joined: 24-Nov-2009
Posts: 8
Post Options Post Options   Quote manishaudio Quote  Post ReplyReply Direct Link To This Post Posted: 05-Jan-2010 at 2:15pm

I am simply trying to obtain the userid from the asp_users table in asp.net security. On the server side I can use the following code:

MembershipUser currentUser;

currentUser = Membership.GetUser(Login2.UserName);

Guid cguid = (Guid)currentUser.ProviderUserKey;

Session.Add("userid", cguid);

this.userguid.Value = cguid.ToString();

What I was looking to do is obtain this from the UserBase.  I don't understand how extending userbase will achieve this functionality.  I probably have to extend the AspAuthenticatingLoginManager and UserBase as well.  
 
Meanwhile, I am passing the user guid to the silverlight app via an html hidden field.  Hopefully, I've clarified things. 
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 05-Jan-2010 at 1:41pm
I'm sorry. I don't mean to be obtuse, but int that tutorial the Silverlight app makes no reference in to System.web nor to the Membership class. It receives an instance of the CustomUser class with the Profile information in it. This instance is accessible through the EntityManager.Principal property on the client. The CustomerUser class abstracts away the dependency on System.web.
 
The server-side code (regular .NET)  does have the System.web reference. I believe that is necessary to support the Web.config where the profile properties are defined. That's how DevForce knows how to populate the CustomUser
 
Perhaps I'm not understanding your question properly.
 
Back to Top
manishaudio View Drop Down
Newbie
Newbie


Joined: 24-Nov-2009
Posts: 8
Post Options Post Options   Quote manishaudio Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jan-2010 at 7:27pm
Hi Ward,

Yes, I have looked at the tutorial but it does not suffice for my purposes. In order to get the userid, you need to reference the Membership class which is in System.web, something which cannot be done Silverlight

I just thought that since userid is quite frequently used in asp.net security design to extend the model, Ideablade would have provided a convenience method. Perhaps in the next release?

The examples only take you so far.
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jan-2010 at 5:56pm
Have you looked at our tutorial on this subject?
 
It's the "ASPNET Profile" tutorial. You can get to it by walking from the Windows Start Menu "IdeaBlade DevForce v??? | Documentation | Learning Resources | Security | 300 Silverlight".
 
On Vista/Win7 it's deployed to disk at: C:\Users\Public\Documents\DevForce\Learning Resources\100_Security\Samples\300SLV\CodeCS\ASPNET Profile
 
The sample assumes some familiarity with ASP.NET Security. If you understand how that works, you'll know how to extend your memberships with additional properties (key/value pairs). You can add "user id" and anything else you want. How you get this information ino the membership database is up to you.
 
If you are not an ASP.NET Security adept ((and I am not adept myself :-) )), you may want to pick up a book on the ASP.NET Security.
 
Once you have such a profile, you can proceed as described in the tutorial. The essential step is this one:
 

Create a CustomUser class - such as the one located in the web project which is also linked from the Silverlight project - with properties corresponding to the profile properties. For DevForce to find and use the custom class, it must extend UserBase, be serializable, and be discoverable as a "known type" via the IKnownType interface or the DiscoverableTypeAttribute.

DevForce will automatically populate the custom properties from the profile during login.

Hope that gets you going in the right direction. Cheers.
Back to Top
manishaudio View Drop Down
Newbie
Newbie


Joined: 24-Nov-2009
Posts: 8
Post Options Post Options   Quote manishaudio Quote  Post ReplyReply Direct Link To This Post Posted: 30-Dec-2009 at 7:43am
Is there a way to get the user id from the UserBase or any other way through DevForce. The name is not enough for my purposes.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down