跨服务器上传文件的俩个例子
来源:互联网 发布:淘宝的快捷方式删不掉 编辑:程序博客网 时间:2024/05/20 02:23
1、添加<identity >标签
<system.web>
......
<identity impersonate="true" userName="域名/用户名" password="口令"></identity>
</system.web>
2、(这种方法我没有测试成功,总是报1314错误)
DllImport("advapi32.dll", SetLastError=true)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
IntPtr tokenHandle = new IntPtr(0);
IntPtr dupeTokenHandle = new IntPtr(0);
string[] args = new string[3];
args[0] = "primos";
args[1] = "066-wangxiaoming";
args[2] = "1234";
const int LOGON32_PROVIDER_DEFAULT = 0;
//This parameter causes LogonUser to create a primary token.
const int LOGON32_LOGON_INTERACTIVE = 2;
//const int SecurityImpersonation = 2;
tokenHandle = IntPtr.Zero;
dupeTokenHandle = IntPtr.Zero;
// Call LogonUser to obtain an handle to an access token.
bool returnValue = LogonUser(args[1], args[0], args[2],
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (!returnValue)
{
GCom.SetClient_Script(Marshal.GetLastWin32Error().ToString());
}
bool retVal = DuplicateToken(tokenHandle, SecurityImpersonation, ref dupeTokenHandle);
//添加逻辑代码
impersonatedUser.Undo();
// Free the tokens.
if (tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);
if (dupeTokenHandle != IntPtr.Zero)
CloseHandle(dupeTokenHandle);
3、
using System.Security.Principal;
...
// Obtain the authenticated user's identity.
WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsImpersonationContext ctx = null;
try
{
// Start impersonating.
ctx = winId.Impersonate();
// Now impersonating.
// Access resources using the identity of the authenticated user.
}
// Prevent exceptions from propagating.
catch
{
}
finally
{
// Revert impersonation.
if (ctx != null)
ctx.Undo();
}
// Back to running under the default ASP.NET process identity.
- 跨服务器上传文件的俩个例子
- Corba的第一个例子
- 委托的二个例子
- MDX的15个例子
- D3D的第一个例子
- 栈的第二个例子
- freemarker的第一个例子
- TC的第一个例子
- webservice的第一个例子
- struts2的第一个例子
- freemarker的第一个例子
- Ajax的第一个例子
- spring的第一个例子
- springAOP的第一个例子
- Netty的第一个例子
- storm的第一个例子
- spring boot 第一个例子pom文件
- 【ajax】xmlHttpRequest 第一个例子 服务器返回的是HTML格式
- Struts2与Struts1的对比
- 重定向 跳出框架结构
- PIX防火墙详细配置命令说明
- Myeclipse5.5GA注册码/破解
- C#中ListView和ImageList配合使用
- 跨服务器上传文件的俩个例子
- 关于Oracle的UPdate与 MSSQL的不同
- 网页系统回到桌面应用时代己来临
- 如何实现一个脚本语言?
- IIS 错误代码大汇总
- 我想看书
- 在NetBeans下使用AppFuse开发Java Web应用
- NetAdvantage控件使用:UltraGrid
- Linux FAQ