0

我需要访问我的用户的 UserId,所以我想这可以通过扩展 user.shared 和 AuthenticationService 来完成。我的目标是在客户端访问 UserId(这是一个“Guid”),默认情况下这是不可能的。

@User.shared 我添加了这些行:

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

这里是 AuthenticationService 类 - 我需要在这里插入什么才能返回 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 给你们所有人——在这个话题上已经浪费了至少 1 个小时:-(。

4

2 回答 2

0

嗯...是的,我可以找到返回字符串的 FriendlyName。但是,我真的不明白这对用户 id 有何帮助?在这里我能找到:

 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 仅包含:

<properties>
        <add name="FriendlyName" />
      </properties>
于 2012-06-02T10:57:34.703 回答
0

如果您查看 Silverlight 业务应用程序模板,就会发现有一个名为 FriendlyName 的 UserProfile。您可以在配置文件中填充 Guid。

于 2012-05-31T22:49:50.983 回答