在ASP.NET应用程序中使用身份模拟 impersonate
2004-07-30 14:23
579 查看
在ASP.NET应用程序中使用身份模拟(Impersonation)
作者: |
Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity currentWindowsIdentity = CType(User.Identity, System.Security.Principal.WindowsIdentity) impersonationContext = currentWindowsIdentity.Impersonate() 'Insert your code that runs under the security context of the authenticating user here. impersonationContext.Undo()Visual C# .NET
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
//Insert your code that runs under the security context of the authenticating user here.
impersonationContext.Undo();在代码中模拟指定的用户帐号 下面的例子在代码中模拟指定的用户帐号: Visual Basic .NET
<%@ Page Language="VB" %><%@ Import Namespace = "System.Web" %><%@ Import Namespace = "System.Web.Security" %><%@ Import Namespace = "System.Security.Principal" %><%@ Import Namespace = "System.Runtime.InteropServices" %>Visual C# .NET
<%@ Page Language="C#"%><%@ Import Namespace = "System.Web" %><%@ Import Namespace = "System.Web.Security" %><%@ Import Namespace = "System.Security.Principal" %><%@ Import Namespace = "System.Runtime.InteropServices" %>下面介绍ASP.NET应用程序中使用身份模拟的一个简单应用。例如有一个ASP.NET应用程序要检查服务器端某个文件是否存在,相应的程序代码为:
bool a = File.Exists("D://Share//test.txt");缺省情况下该ASP.NET应用程序以ASPNET帐号运行。为了安全起见,ASPNET这个帐号并没有服务器端D:/Share/这个目录的访问权限。在不使用身份模拟的情况下,由于ASP.NET应用程序不具有访问该目录的权限,无论文件是否存在,File.Exists的返回值将永远是false。为了解决这个问题,可以另建一个用户帐号:FileExist,并赋予该帐号D:/Share/目录的访问权限。然后在该应用程序的Web.config文件的标记中指定具体的用户帐号: 来执行该程序。 更多信息 请访问以下链接获取更多信息: 1. INFO: Implementing Impersonation in an ASP.NET Application http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306158&SD=MSKB 2. INFO: ASP.NET Security Overview http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306590 3. ASP.NET Web Application Security http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspnetwebapplicationsecurity.asp 作者:黄雪斌
为什么impersonate的例子在我机器上不行Posted: 31 May 2004 09:39 AM |
我知道原因了The LogonUser API has been available and documented since Windows NT 3.51, and is commonly used to verify user credentials. This API is available on Windows NT, Windows 2000, and Windows XP. Unfortunately, there are some restrictions on using LogonUser that are not always convenient to satisfy.The first and biggest of these restrictions is that on Windows NT and Windows 2000, the process that is calling LogonUser must have the SE_TCB_NAME privilege (in User Manager, this is the "Act as part of the Operating System" right).不过我怎么设置"Act as part of the Operating System" right??? |
相关文章推荐
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟+2.0
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 转: 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 实例在ASP.NET应用程序中使用身份模拟
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- 在ASP.NET应用程序中使用身份模拟(Impersonation)
- asp.net 的应用程序身份和模拟
- 通过使用客户端证书调用 Web 服务以便在 ASP.NET Web 应用程序中进行身份验证