Web Parts, Impersonate and Security Policy, Part 2

该博客继续前文,阐述SharePoint Web Parts开发中访问权限问题的解决办法。前文用C#示例代码演示了impersonate应用,这里贴出VB.Net代码方便使用VB.Net的情况,且文章未完,Part 3待续。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Web Parts, Impersonate and Security Policy

Part 2

 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Written by: Rickie Lee (rickieleemail at yahoo.com)

继续前面的postingWeb Parts, Impersonate and Security Policy, Part 1》,阐明如何解决SharePoint Web Parts开发过程中访问权限的问题。Part 1中以C#的示例代码演示了impersonate(角色扮演)的应用。

这里简单贴出VB.Net代码,方便使用VB.NetCASE

Protected Shared Function CreateIdentity(ByVal User As String, _

ByVal Domain As String, ByVal Password As String) As WindowsIdentity

 

    Dim objToken As New IntPtr(0)

    Dim ID As WindowsIdentity

    Const LOGON32_PROVIDER_DEFAULT As Integer = 0

    Const LOGON32_LOGON_NETWORK As Integer = 3

 

    'Initialize token object

    objToken = IntPtr.Zero

 

    ' Attempt to log on

    Dim blnReturn As Boolean = LogonUser(User, Domain, Password, _

    LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, objToken)

 

    'Check for failure

    If blnReturn = False Then

        Dim intCode As Integer = Marshal.GetLastWin32Error()

        Throw New Exception("Logon failed: " & intCode.ToString)

    End If

 

    'Return new token

    ID = New WindowsIdentity(objToken)

    CloseHandle(objToken)

    Return ID

 

End Function

 

<DllImport("advapi32.dll", SetLastError:=True)> _

    Private Shared Function LogonUser(ByVal lpszUsername As String, _

ByVal lpszDomain As String, _

ByVal lpszPassword As String, ByVal dwLogonType As Integer, _

ByVal dwLogonProvider As Integer, _

        ByRef phToken As IntPtr) As Boolean

End Function

 

<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _

    Private Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean

End Function

 

***

未完,Part 3待续.

 

Reference:

1. Rickie Lee, Web Parts, Impersonate and Security Policy, Part 1, you can reach Rickie Lee at rickieleemail (at) yahoo.com.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值