我需要访问我的用户的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个小时: - (。
答案 0 :(得分:0)
如果您查看Silverlight业务应用程序模板,则会有一个名为FriendlyName的UserProfile。你可以在配置文件中填充Guid。
答案 1 :(得分: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>