0

这是代码,我正在使用此代码在共享点的列表中插入数据。如果用户有权限,则此代码将数据插入列表。如果用户没有权限,那么它会引发错误访问被拒绝。如何克服这一点?

Protected Sub Btn_Registration_Click(ByVal sender As Object, ByVal e As                                                      System.EventArgs) Handles Btn_Registration.Click
    SPSecurity.RunWithElevatedPrivileges(AddressOf TcregistrationRun)
End Sub
Public Sub TcregistrationRun()     
            Dim _TCNricNum As String = Session("IC").ToString
            Dim _Msite As SPSite = New SPSite(SPContext.Current.Site.Url)
            Dim _MWeb As SPWeb = _Msite.OpenWeb("/Admin")
            _MWeb.AllowUnsafeUpdates = True              
            NewEnTry.Update()
            _MWeb.AllowUnsafeUpdates = False 
End Sub
4

1 回答 1

1

试试这个...在调用中创建一个新的 Web 实例和一个新的站点实例,以便以提升的权限运行。这将确保您拥有更高权限下的新实例。如果您允许在您的网站上进行匿名访问,它应该可以工作。请参阅此处的线程。您还需要记住在方法调用中获取列表的实例。

using (SPSite site = new SPSite(SPContext.Current.Site.ID)) 
{ 
   using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID]) 
   { 
      web.AllowUnsafeUpdate = true; 

      // Get instance of list item and set the values 

      // Call update on the list item

      web.AllowUnsafeUpdate = false;
   } 
}
于 2012-05-17T08:35:49.980 回答