无法在事件处理程序中将用户添加到 Sharepoint 2010

发布于 2024-10-07 09:52:42 字数 500 浏览 2 评论 0原文

使用同步和异步事件处理程序(itemAdded 和 itemAdding),我无法使用基于表单的身份验证将用户添加到我的 Sharepoint 2010 站点(我知道该身份验证已正确设置和工作,因为它在 Sharepoint 中一直运行良好)据我所知,UI)

调用 Membership.CreateUser 不起作用,并且不断抛出“对象引用未设置到对象实例”的异常。调试并查看会员资格,很明显出现了问题。大多数成员为空或抛出异常。我知道会员资格在应用程序页面中没有这个问题(我可以从应用程序页面添加用户、将它们添加到组等,但它在事件处理程序内部失败)。我们最初认为这是一个 HttpContext 问题,但我们可以在 itemAdding() 中获取 HttpContext.Current,因此这可能没有太大区别。

有什么线索吗?是否可以在事件处理程序中将用户添加到 SP2010?

背景:当我向列表(带有电子邮件列)添加新行时,将向具有指定电子邮件地址的用户授予权限 - 如果该用户不存在,我想创建它(同样,对于基于表单的身份验证)

Using both synchronous and asycnhronous event handlers (itemAdded and itemAdding), I have been unable to add a user to my Sharepoint 2010 site - using Forms Based Authentication (which I know to be properly setup and working because it has been working perfectly from the Sharepoint UI from what I can tell)

Calling Membership.CreateUser is not working and constantly throws an exception of "object reference not set to an instance of an object". Debugging and looking into Membership, it is clear that something is wrong. Most members are null or throw exceptions as well. I know Membership doesn't have this issue in an Application Page (I can add users, add them to groups, etc.. from an Application page, but it fails inside of an event handler). We originally thought it was a HttpContext issue, but we can get HttpContext.Current inside itemAdding(), so that might not make much difference.

Any clues? Is it possible to add users to SP2010 within an event handler?

Background: when I add a new row to a list (with an Email column), permissions are granted to the user with the specified email address - if that user doesn't exist I want to create it (again, for Forms Based Authentication)

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

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

发布评论

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

评论(2

戒ㄋ 2024-10-14 09:52:42

我从未做过任何共享点开发,但这听起来像是跨线程问题。该事件将创建一个新线程,该线程无法访问包含“会员资格”的线程。尝试使用委托传递它?
例如

Object.ItemAdded+= (o, args) => Class.Method(o, args, Membership);

Im have never done any share point development but it sounds like a cross thread problem.. The event will create a new thread which wont have acces to the thread that contains 'Membership'. try passing it through using a delegate?
eg

Object.ItemAdded+= (o, args) => Class.Method(o, args, Membership);
时光磨忆 2024-10-14 09:52:42

在我看来,你的 httpcontext.current 为空。至少我遇到了同样的问题,这就是原因。
检查这个http://kbochevski.blogspot.com/2011/01 /accessing-membership-database-inside.html
我希望它可能有帮助

It seems to me that your httpcontext.current is null. At least i had the same problem and that was the reason.
Check this http://kbochevski.blogspot.com/2011/01/accessing-membership-database-inside.html
I hope it may be of help

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