posts - 5,  comments - 5,  trackbacks - 0

          using Microsoft.SharePoint.WebControls;
          using Microsoft.Web.UI.WebControls;
          private void Button1_Click(object sender, System.EventArgs e)
          ??{
          ???//模擬用戶
          ???//WindowsImpersonationContext wic = CreateIdentity("ssa_sps03","paicdom","spstestA1").Impersonate();
          ???List list = new List();
          ???list.AddList(tb_NewsTitle.Text);
          ???//wic.Undo();
          ??}

          ??protected static WindowsIdentity CreateIdentity(string User, string Domain, string Password)
          ??{
          ???// The Windows NT user token.
          ???IntPtr tokenHandle = new IntPtr(0);

          ???const int LOGON32_PROVIDER_DEFAULT = 0;
          ???const int LOGON32_LOGON_NETWORK = 3;

          ???tokenHandle = IntPtr.Zero;

          ???// Call LogonUser to obtain a handle to an access token.
          ???bool returnValue = LogonUser(User, Domain, Password,
          ????LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
          ????ref tokenHandle);

          ???if (false == returnValue)
          ???{
          ????int ret = Marshal.GetLastWin32Error();
          ????throw new Exception("LogonUser failed with error code: " +? ret);
          ???}

          ???System.Diagnostics.Debug.WriteLine("Created user token: " + tokenHandle);

          ???//The WindowsIdentity class makes a new copy of the token.
          ???//It also handles calling CloseHandle for the copy.
          ???WindowsIdentity id = new WindowsIdentity(tokenHandle);
          ???CloseHandle(tokenHandle);
          ???return id;
          ??}

          ??[DllImport("advapi32.dll", SetLastError=true)]
          ??private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
          ???int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

          ??[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
          ??private extern static bool CloseHandle(IntPtr handle);
          ?}

          posted on 2006-12-04 10:31 曾科 閱讀(391) 評論(0)  編輯  收藏 所屬分類: C#
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          .net

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永嘉县| 蓝田县| 平邑县| 嵊泗县| 桦甸市| 定边县| 莱州市| 河源市| 江口县| 蓬溪县| 瑞丽市| 剑阁县| 什邡市| 广元市| 莲花县| 繁昌县| 靖州| 腾冲县| 定南县| 辽源市| 思南县| 浮梁县| 丰宁| 余江县| 昌黎县| 潜江市| 会昌县| 临沧市| 大庆市| 临沂市| 昌黎县| 三门县| 唐河县| 元谋县| 西吉县| 高雄县| 石景山区| 泗水县| 罗甸县| 兴安县| 大英县|