zoukankan      html  css  js  c++  java
  • Web Parts, Impersonate and Security Policy, Part 2

    Web Parts, Impersonate and Security Policy

    Part 2

     

    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.

     

  • 相关阅读:
    MyEclipse Servers视窗出现“Could not create the view: An unexpected exception was thrown”错误解决办法
    eclipse 安装git
    使用Maven构建Web项目
    Maven仓库构建
    JAX-WS:背后的技术JAXB及传递Map
    CXF WebService 开发文档
    eclispse 中集成多个tomcat
    Myeclipse 主题下载
    html textarea 获取换行
    jqurey click和blur执行时间冲突
  • 原文地址:https://www.cnblogs.com/rickie/p/97895.html
Copyright © 2011-2022 走看看