模拟和的NetworkCredential [英] Impersonation and NetworkCredential

查看:307
本文介绍了模拟和的NetworkCredential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过的NetworkCredential 对象与当前模拟用户从一个asp.net应用程序的Web服务的凭证。结果
我的code是这样的:

I need to pass a NetworkCredential object with the credentials of the currently impersonated user to a web service from an asp.net application.
My code looks like this:

WindowsIdentity windowsIdentity = HttpContext.Current.User.Identity as WindowsIdentity;
WindowsImpersonationContext context = windowsIdentity.Impersonate();
try {
    var client = GetClient();
    client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
    Log("WindowsIdentity = {0}", windowsIdentity.Name);
    Log("DefaultNetworkCredentials = {0}", CredentialCache.DefaultNetworkCredentials.UserName);
    client.DoSomething();
} finally {
    context.Undo();
}

我的理解是, CredentialCache.DefaultNetworkCredentials 应该给当前模拟用户的凭据,但事实并非如此。结果
日志消息我得到的是

I had understood that CredentialCache.DefaultNetworkCredentials should give the credentials of the currently impersonated user, but it is not the case.
The log messages I get are

WindowsIdentity = TESTDOMAIN\TESTUSER
DefaultNetworkCredentials = 

我是不是做错了什么?如果是这样,你怎么一个的NetworkCredential对象为目前模拟的用户?

Am I doing something wrong? If so, how do you get a NetworkCredential object for the currently impersonated user?

推荐答案

在MSDN稍长的文章,解释的选项来获得ASP的网络凭据:

A somewhat lengthy article in MSDN explaining the options to obtain network credentials in ASP:

如何:使用模拟和代表团在ASP.NET 2.0中

How To: Use Impersonation and Delegation in ASP.NET 2.0

在话题的另一个博客文章(虽然我没有检查解决方案是否确实有效:

Another blog article on the topic (though I didn't check whether the solution actually works:

<一个href=\"http://platinumdogs.word$p$pss.com/2008/10/30/net-c-impersonation-with-network-credentials/\">.NET (C#)模拟与网络凭据

.NET (C#) Impersonation with Network Credentials

这篇关于模拟和的NetworkCredential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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