【发布时间】:2016-03-11 09:44:24
【问题描述】:
我有一个 silverlight 客户端和 wcf 服务。应用有3种认证方式
- 活动目录
- Windows 直通
- 专有的 - 我对这个显然没有问题。 (我真的不知道活动目录和窗口传递有什么区别。我只是对两者使用相同的代码,除了窗口传递我得到当前用户和 AD 应用程序提示输入用户名密码)李>
.
private string GetCurrentUser()
{
try
{
string result = WindowsIdentity.GetCurrent().Name;
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
result = wp.Identity.Name;
if (result.Contains(@"\"))
{
int position = result.LastIndexOf(@"\") + 1;
result = result.Substring(position);
}
return result;
}
catch (Exception ex)
{
return "";
}
}
WindowsIdentity 和 WindowsPrincipal 都返回“DefaultAppPool”或当前线程运行的任何 AppPool。甚至 Environment.UserName 返回相同。
当我在 web.config 中打开 <identity impersonate ="true"/> 时,silverlight 客户端无法连接到 wcf。它收到“未找到”错误。所以,我需要保留<identity impersonate ="false"/>
我只需要当前登录的用户,没想到这么难。
【问题讨论】:
-
我也遇到了同样的问题(虽然它不是 Silverlight 应用程序) - 你解决了吗?
-
请查看答案,我刚刚更新了。
标签: wcf-security