0

I need to access the UserId of my Users, so I guess this can be done by extending user.shared and AuthenticationService. It is my goal to access the UserId (which is a "Guid") at the client side, by default this is not possible.

@ User.shared I added these lines:

/// <summary>
/// Gets the UserId of the user.
/// </summary>
public Guid UserId { get; private set; }

Here the AuthenticationService class - what do I need to insert here in order to return the UserId ??

[EnableClientAccess]
public class AuthenticationService : AuthenticationBase<User> 
{ 
    //adapt GetAuthenticatdUser in order to be able to retrieve the UserId @ the client !
    protected override User GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)
    {

        return base.GetAuthenticatedUser(principal);
        //what does this line above actually do ?!!?

        //INSERT statement which returns the UserId (Guid)
    }
}

THX to all of you guys - have lost at least 1 hour already on this topic :-(.

2 Answers2

0

If you have a look at the Silverlight Business Application template, there is a UserProfile called FriendlyName. You can stuff the Guid in the profile.

Chui Tey
  • 5,436
  • 2
  • 35
  • 44
  • Dear Chui Tey, thank you for your reply! Unfortunately I don't know HOW to do that. I am a C# student, our lecturer is not available and noone can help me :-( – SWEapprentice Jun 01 '12 at 08:31
  • Did you find the FriendlyName entry in the source code? If you are a programming student, then you must learn at least one tool that will search through files for some text. – Chui Tey Jun 02 '12 at 05:46
0

Well...yes, I could find FriendlyName, which returns a string. However, I do not really understand how this helps me regarding the user id ? here what I could find:

 public partial class User
    {
        /// <summary>
        /// Returns the user display name, which by default is its FriendlyName.
        /// If FriendlyName is not set, the User Name is returned.
        /// </summary>
        public string DisplayName
        {
            get
            {
                if (!string.IsNullOrEmpty(this.FriendlyName))
                {
                    return this.FriendlyName;
                }
                else
                {
                    return this.Name;
                }
            }
        }

        /// <summary>
        /// Gets the UserId of the user.
        /// </summary>
        public Guid UsrId { get; private set; } //I added this line
        //this doesnt really work yet - don't know how to access the actual guid :-(
    }



/// <summary>
    /// Class containing information about the authenticated user.
    /// </summary>
    public partial class User : UserBase
    {
        //// NOTE: Profile properties can be added for use in Silverlight application.
        //// To enable profiles, edit the appropriate section of web.config file.
        ////
        //// public string MyProfileProperty { get; set; }

        /// <summary>
        /// Gets and sets the friendly name of the user.
        /// </summary>
        public string FriendlyName { get; set; }


    }

Web.config only contains:

<properties>
        <add name="FriendlyName" />
      </properties>