从WCF服务端获取Windows用户名 [英] Get Windows Username from WCF server side

查看:116
本文介绍了从WCF服务端获取Windows用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢绿色与Web服务和WCF和我使用Windows集成身份验证 - 如何获取服务器端界面上的用户名?我相信,我应该实现一个自定义的行为,或与WCF会话也许什么?任何线索将是超级方便。

I'm pretty green with web services and WCF, and I'm using Windows integrated authentication - how do I get the username on the server-side interface? I believe that I'm supposed to implement a custom Behavior, or perhaps something with WCF Sessions? Any clues would be super-handy.

推荐答案

下面是服务代码片段展示了如何获取并使用的WindowsIdentity与WCF服务的调用者相关联。

Here is a snippet of service code that shows how you could retrieve and use the WindowsIdentity associated with the caller of a WCF service.

此代码是假设你是最接受您的配置的默认值。这样就没有与命名管道或TCP净绑定任何问题。

This code is assuming that you are accepting most of the defaults with your configuration. It should work without any problems with the Named Pipe or the Net TCP binding.

p.Demand()将确定用户是否是由permissionGroup变量指定的窗口组中使用。

the p.Demand() will determine if the user is in the windows group specified by the permissionGroup variable.

private static void DemandManagerPermission()
{
    // Verify the use has authority to proceed
    string permissionGroup = ConfigurationManager.AppSettings["ManagerPermissionGroup"];
    if (string.IsNullOrEmpty(permissionGroup))
    	throw new FaultException("Group permissions not set for access control.");

    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
    var p = new PrincipalPermission(ServiceSecurityContext.Current.WindowsIdentity.Name, permissionGroup, true);
    p.Demand();

}

这篇关于从WCF服务端获取Windows用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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