我需要在VMWare机器上运行的ASP.NET应用程序中模拟自己作为域用户。 由于VMWare机器本身不在域中,因此ASP.NET无法parsing用户令牌(在web.config中指定)。 有没有办法做到这一点?
在此先感谢,彼得
无法在IE10浏览器中模拟IE7
部署Windows Mobile 6专业模拟器应用程序
为什么Windows不允许在模仿其他用户时启动WinSock
.Net类来控制远程机器上的服务?
babun:从Windows剪贴板复制/粘贴到VIM?
我使用这个我一直写的课程,它的功能就像一个魅力!
using System; using System.Security.Principal; /// <summary> /// Changes the security context the application runs under. /// </summary> public class ImpersonateHelper : IDisposable { [System.Runtime.InteropServices.DllImport("coreel32")] private extern static Boolean CloseHandle(IntPtr handle); private IntPtr _token = IntPtr.Zero; private WindowsImpersonationContext _impersonatedUser = null; public IntPtr Token { get { return _token; } set { _token = value; } } public ImpersonateHelper(IntPtr token) { _token = token; } /// <summary> /// Switch the user to that set by the Token property /// </summary> public void Impersonate() { if (_token == IntPtr.Zero) _token = WindowsIdentity.GetCurrent().Token; _impersonatedUser = WindowsIdentity.Impersonate(_token); } /// <summary> /// Revert to the identity (user) before Impersonate() was called /// </summary> public void Undo() { if (_impersonatedUser != null) _impersonatedUser.Undo(); } #region IDisposable Members private bool _isDisposed; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { if (_impersonatedUser != null) _impersonatedUser.Dispose(); } CloseHandle(_token); _token = IntPtr.Zero; } _isDisposed = true; } ~ImpersonateHelper() { Dispose(false); } #endregion }
然后你从客户端类中调用它:
//Run task as the impersonated user and not as NETWORKSERVICE or ASPNET (in IIS5) try{ impersonate.Impersonate(); //Do work that needs to run as domain user here... } finally { //Revert impersonation to NETWORKSERVICE or ASPNET if (impersonate != null) { impersonate.Undo(); impersonate.Dispose(); } }
祝你好运!
这可能是愚蠢的明显的答案,但你可以添加你的VMWare机器的域名。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。