0

使用 C# 匿名委托,我们可以避免声明额外的方法,我知道在 VB.NET 中它们不可用,但是有没有我可以使用的设计模式,这样我就可以避免每次都编写额外的方法?我需要它用于 SPSecurity.RunWithElevatedPrivileges,它将在我们的代码中使用很多次。

例如

SPSecurity.RunWithElevatedPrivileges(
                    delegate()
                    {
                        //some code here. 
                    }
                );

我希望在 VB.NET 中执行以下操作:

using RunWithElevatedPrivil() 
'some code here. 
end using 
4

1 回答 1

4

检查此链接,它可能会有所帮助:

http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/4854962a-0d4e-40e4-909a-581bb7a5ab03

在 vb.net 中,您可以定义一个无参数子程序,该子程序执行您希望以更高权限执行的代码,并将其声明为 CodeToRunElevated:

您必须定义模块级变量才能使用。

将安全代码调暗为新 SPSecurity.CodeToRunElevated(AddressOf Me.SPCode) SPSecurity.RunWithElevatedPrivileges(secureCode)

于 2012-04-18T21:05:36.587 回答