你如何获得证书(的NetworkCredential)的当前登录的用户? [英] How do you get credentials (NetworkCredential) of currently logged in user?

查看:1921
本文介绍了你如何获得证书(的NetworkCredential)的当前登录的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一些code利用第三方组件,我需要提供一个对象,它实现了ICredentials当我开始使用它。

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");

...并通过凭证,它的罚款。但我想通过当前用户的凭据的(这是一个Windows服务,从而为特定用户运行)的。

我已经试过两个以下,但既不似乎工作的(或返回任何东西)的:

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;

任何人都可以建议如何获得一个approriate对象,从而重新presents的用户名,该服务在其下运行的凭据?

Can anyone suggest how to acquire an approriate object, which represents the credentials of the username that the service is running under ?

谢谢, 罗斯

推荐答案

你试过WindowsIdentity.GetCurrent()?

have you tried WindowsIdentity.GetCurrent()?

您也可以看看下面这个例子...... HTTP:// WWW 。codeproject.com / KB / VB / Windows_Service.aspx

you could also look at this example... http://www.codeproject.com/KB/vb/Windows_Service.aspx

这篇关于你如何获得证书(的NetworkCredential)的当前登录的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆