I'm writing some code to utilise a 3rd party component, and I need to supply an object which implements ICredentials when I start to use it.
If I write the following...
var credential = new NetworkCredential("MyUsername", "MyPassword");
...and pass "credential", it's fine. But I would like to pass the credentials of the current user (it's a Windows service, so runs as a specified user).
I have tried both of the following, but neither appear to work (or return anything):
NetworkCredential credential = System.Net.CredentialCache.DefaultCredentials; NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;
Can anyone suggest how to acquire an approriate object, which represents the credentials of the username that the service is running under ?
Thanks
For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.
have you tried WindowsIdentity.GetCurrent()?
you could also look at this example... http://www.codeproject.com/KB/vb/Windows_Service.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With