具有自定义会员资格提供商的 FBA 显示名称,WSS 3.0

发布于 2024-08-14 13:10:31 字数 497 浏览 3 评论 0原文

我有一个 WSS 3.0 站点(无 MOSS),它使用自定义表单身份验证成员资格提供程序和角色管理器,根据远程 Web 服务对用户进行身份验证(尽管目前它适用于起订量数据)。我的问题是这样的:用户登录时显示的名称是他们的登录名,而不是全名。

我设置了我的提供程序,以便存储用户名和全名,并且当询问时(例如 GetUserByUsername),任一值都将返回一个以全名作为用户名的 MembershipUser 对象。这样的效果是,在共享点人员选择器中,输入用户用户名会自动完成将其转换为全名,就像标准 Windows 身份验证一样。

但是,在提供程序上设置断点,当登录到站点时,仅调用提供程序上的 ValidateUser 方法,它们永远不会请求我修改过的 MembershipUser 对象。查看内容数据库中的 UserInfo 表,将创建一个新条目,并将用户名 (tp_title) 设置为其登录名。

如果没有对数据库运行直接查询(我不会这样做),我不确定如何为自定义 FBA 用户提供用户友好的用户名。如有帮助,将不胜感激。

I have a WSS 3.0 site (no MOSS) that uses a custom forms authentication membership provider and role manager, authenticating users against a remote web service (although at the moment it works against moq data). My problem is this: users when logged in have their name shown as being their login name, not their full name.

I set up my provider so that both the username and fullname are stored, and that when asked (e.g. GetUserByUsername) either value will return a MembershipUser object with the Fullname as the username. This has the effect that in the sharepoint people picker, entering a users username results in the auto complete turning it into their fullname, much like the standard windows auth does.

However, breakpointing the provider, when logging in to the site only the ValidateUser method on the provider is called, their is never a request for my doctored MembershipUser objects. Looking at the UserInfo table in the content database a new entry is created with the user name (tp_title) set to their login name.

Short of running a direct query against the database (which I am not going to do) I am unsure how I can have a user friendly username for custom FBA users. Help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Bonjour°[大白 2024-08-21 13:10:31

没关系,找到了解决办法。在我的自定义成员资格提供程序的验证用户方法上,以下代码允许我设置 name 属性。当使用数千个用户时,这可能无法扩展,但对于小型用户群来说应该没问题:

public override bool ValidateUser(string username, string password)
    {
        if (moqUsers.Any(user => user.Username.Equals(username) && user.Password.Equals(password)))
        {
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = true;
            var user = SPContext.Current.Site.RootWeb.EnsureUser(username);
            user.Name = RetrieveUserFullName(username);
            user.Update();
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = false;
            return true;
        }
        return false;
    }

此外,上面可能需要对 rootweb 进行良好的处理。

Nevermind, found a way around it. On the validate user method of my custom membership provider, the following code allows me to set the name property. This might not scale when using thousands of users, but for small user bases it should be fine:

public override bool ValidateUser(string username, string password)
    {
        if (moqUsers.Any(user => user.Username.Equals(username) && user.Password.Equals(password)))
        {
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = true;
            var user = SPContext.Current.Site.RootWeb.EnsureUser(username);
            user.Name = RetrieveUserFullName(username);
            user.Update();
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = false;
            return true;
        }
        return false;
    }

Also, there might need to be a good disposal of rootweb in the above.

诗酒趁年少 2024-08-21 13:10:31

我尝试了很多方法来让上面的代码在 ValidateUser 期间正常工作,我认为这是更新 UserInfo.tp_Title 的好时机(也许除了您每次用户登录时都会更新它,但是嘿,你要做什么?)。

但是,我无法让 EnsureUser 正常运行(也尝试过 AllUsers[])而不抛出错误。尝试在 SPSecurity.RunWithElevatedPrivileges 等下的匿名委托中执行。没有骰子。

但事实是,我认为这完全是正确的想法,我只是想分享我让它工作的方式是通过调用 SP UserGroup Web 服务 (/ _vti_bin/usergroup.asmx),调用UpdateUserInfo。对我来说确切的方法签名看起来像:

UserGroup.UpdateUserInfo("custommembershipprovidername:" + username, TheFullName,
 emailAddress, string.Empty)

I tried a lot to get the code above to work during ValidateUser, which I think is a great time to update UserInfo.tp_Title (except maybe for the fact that you're going to update it every time the user logs in, but hey, what are you going to do?).

However, I was unable to get EnsureUser to function (also tried AllUsers[]) without throwing errors. Tried executing within an anonymous delegate under SPSecurity.RunWithElevatedPrivileges and all. No dice.

Thing is, though, that I think this is totally the right idea, and I just want to share that the way I got it working is through a call to the SP UserGroup web service (/_vti_bin/usergroup.asmx), calling UpdateUserInfo. The exact method signature for me looks something like:

UserGroup.UpdateUserInfo("custommembershipprovidername:" + username, TheFullName,
 emailAddress, string.Empty)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文