Authenticating against a remote server and domain (C#/3.5)
I have a .Net 3.5 service that runs on a stand-alone computer. The service queries the event logs of servers in multiple Active Directory domains. I would like to authenticate to these using managed code.
Currently, I authenticate either with p/invoke to WNetAddConnection2A or w开发者_如何学JAVAith processing out with a net use. For example, this works:
string user = "domain\\administrator";
string pass = "password";
string server = "server.domain.com";
string argument = String.Format("use \\\\{0}\\ipc$ /user:{1} {2}", server, user, pass);
System.Diagnostics.Process.Start("net.exe", argument);
System.Diagnostics.EventLog log = new EventLog("System", server);
Is there a way in the .Net 3.5 framework to authenticate and read the event log without having to proc out or call unmanaged code?
Have you seen the "System.Security.Principal.WindowsImpersonationContext" and the demo written in MSDN.
Way back, in the .NET 1.1 days, I had to write a windows service for validation of users in 2 windows domains, used LDAP - and WindowsImpersonation as fail-back.
As I remember I got insperation form CodeProject and Google :-S
/Erling Damsgaard DNS-IT ApS
精彩评论