如何在 Windows SharePoint Services 3.0 中运行具有提升权限的命令?

发布于 2024-08-21 09:18:23 字数 1224 浏览 6 评论 0原文

我正在使用表单身份验证登录到 windows sharepoint services 3.0 服务。 我需要在匿名访问期间提升将记录添加到共享点门户列表的权限。

我在msdn中找到了线索: http://msdn.microsoft.com/en-us/ Library/bb466220%28classic%29.aspx

但这对我不起作用。 :( 它仍然要求用户登录名和密码。

有人可以帮助我吗?

Public Function AddUserAccountData() As String
        SPSecurity.RunWithElevatedPrivileges(AddressOf AddUserAccountDataToSPList)
        Return ""
    End Function

    Private Sub AddUserAccountDataToSPList()
        Dim oSharedConfig As SharedConfig = SharedConfig.Instance
        Dim sListName As String = oSharedConfig.oWebPartsOpt.UserOpt.AccountVerificationList.Name

        Using oSite As SPWeb = SPContext.Current.Web
            Dim oUserAccStatusList As SPList = oSite.Lists(sListName)

            oUserAccStatusList.Items.Add()
            Dim oSPListItem As SPListItem = oUserAccStatusList.Items.Add()

            oSPListItem("one") = _sUserLogin
            oSPListItem("two") = _sUserGuid
            oSPListItem("three") = False
            oSPListItem("four") = DateTime.Now

            oSPListItem.Update()
        End Using
    End Sub

I'm using forms authentication to log in into windows sharepoint servevices 3.0 service.
I need to elevate during anonymous access, rights to add record to sharepoint portal list.

I found clue in msdn:
http://msdn.microsoft.com/en-us/library/bb466220%28classic%29.aspx

But it doesn't work for me. :( It's still calling for user login and password.

Can anybody help me please?

Public Function AddUserAccountData() As String
        SPSecurity.RunWithElevatedPrivileges(AddressOf AddUserAccountDataToSPList)
        Return ""
    End Function

    Private Sub AddUserAccountDataToSPList()
        Dim oSharedConfig As SharedConfig = SharedConfig.Instance
        Dim sListName As String = oSharedConfig.oWebPartsOpt.UserOpt.AccountVerificationList.Name

        Using oSite As SPWeb = SPContext.Current.Web
            Dim oUserAccStatusList As SPList = oSite.Lists(sListName)

            oUserAccStatusList.Items.Add()
            Dim oSPListItem As SPListItem = oUserAccStatusList.Items.Add()

            oSPListItem("one") = _sUserLogin
            oSPListItem("two") = _sUserGuid
            oSPListItem("three") = False
            oSPListItem("four") = DateTime.Now

            oSPListItem.Update()
        End Using
    End Sub

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

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

发布评论

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

评论(2

一抹微笑 2024-08-28 09:18:23

使用 RunWithElevatedPrivileges 时,不应使用 SPContext.Current - 它仍然具有旧的权限。您应该重新打开 SPWeb 以赋予其正确的权限。在您的链接代码上,这是通过以下行完成的:

using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID))

来源:
RunWithElevatedPrivileges,注意网站上下文
将项目添加到 SharePoint 列表 - 来自我的博客,可能会帮助您解决下一个问题。

另请注意:您不应该编写 Using oSite As SPWeb = SPContext.Current.WebSPContext 对象不应由您处置 - 它们在不同组件之间共享,因此可能会导致其他异常。
这是一个常见的错误 - 在我看来,API 可以做得更好。

When using RunWithElevatedPrivileges you shouldn't use SPContext.Current - it still has the old permissions. You should reopen your SPWeb to give it the right permissions. On your linked code this is done by the lines:

using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID))

Source:
RunWithElevatedPrivileges, watch out for the site context
Adding Items to a SharePoint List - from my blog, might help with your next problem.

Another note: you should not be writing Using oSite As SPWeb = SPContext.Current.Web. SPContext objects should not be disposed by you - they are shared between different components, so it may lead to other exceptions.
This is a common mistake - it could have been done better by the API in my opinion.

与往事干杯 2024-08-28 09:18:23

线路

oUserAccStatusList.Items.Add()

看起来有点不对劲。引用 SPList 后,您可以通过调用 listItem 上的 Items.Add 来创建一个新的 listItem,如以下代码所示>,设置属性,然后调用 Update 方法。

The line

oUserAccStatusList.Items.Add()

Looks a little off. Once you have a reference to the SPList you create a new listItem like you have in the following code, by calling the Items.Add on the listItem, set your properties and then call the Update method.

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