如何在 Windows SharePoint Services 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
RunWithElevatedPrivileges
时,不应使用SPContext.Current
- 它仍然具有旧的权限。您应该重新打开SPWeb
以赋予其正确的权限。在您的链接代码上,这是通过以下行完成的:来源:
RunWithElevatedPrivileges,注意网站上下文
将项目添加到 SharePoint 列表 - 来自我的博客,可能会帮助您解决下一个问题。
另请注意:您不应该编写
Using oSite As SPWeb = SPContext.Current.Web
。SPContext
对象不应由您处置 - 它们在不同组件之间共享,因此可能会导致其他异常。这是一个常见的错误 - 在我看来,API 可以做得更好。
When using
RunWithElevatedPrivileges
you shouldn't useSPContext.Current
- it still has the old permissions. You should reopen yourSPWeb
to give it the right permissions. On your linked code this is done by the lines: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.
线路
看起来有点不对劲。引用 SPList 后,您可以通过调用
listItem
上的Items.Add
来创建一个新的listItem
,如以下代码所示>,设置属性,然后调用Update
方法。The line
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 theItems.Add
on thelistItem
, set your properties and then call theUpdate
method.