简体   繁体   English

使用Windows身份验证的WPF应用程序

[英]WPF application with Windows authentication

I have a simple wpf client (few text boxes) that uploads some data to a web service. 我有一个简单的wpf客户端(几个文本框),可以将一些数据上传到Web服务。 And I want to use windows authentication to go with my application. 我想使用Windows身份验证来使用我的应用程序。

I am checking in OnStartup of App.xaml, whether or not the user is authenticated. 我正在检查App.xaml的OnStartup,无论用户是否经过身份验证。 My question is around what is the meaning of Thread.CurrentPrincipal.Identity.IsAuthenticated. 我的问题是关于Thread.CurrentPrincipal.Identity.IsAuthenticated的含义是什么。

I don't want my application to be used from outside my network as it is connecting to a web service and uploads data. 我不希望我的应用程序在网络外部使用,因为它连接到Web服务并上传数据。 But my assumption is as long as you run this application from inside any windows network the above mentioned property will always return true? 但我的假设是,只要您从任何Windows网络中运行此应用程序,上述属性将始终返回true?

So how do I find out if the application is being run from inside my network. 那么如何确定应用程序是否从我的网络内部运行。 I don't think checking domain name or role name is any different, because I can always setup a domain and name it whatever I want. 我不认为检查域名或角色名称是否有任何不同,因为我总是可以设置域名并将其命名为我想要的任何名称。 I don't want to prompt user for username or password of any sort. 我不想提示用户输入任何类型的用户名或密码。

How do you check Identity of user against a particular AD (AD might not be publically available). 如何检查用户对特定AD的身份(AD可能不是公开可用的)。 Basically the application should only works from my local network or through VPN. 基本上,应用程序只能在我的本地网络或VPN上运行。

var context = new PrincipalContext(ContextType.Domain, "DOMAINNAME");
var result = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userName);

If the result is null, then the user does not exists in the AD domain. 如果结果为null,则AD域中不存在该用户。

You can also user DirectorySearcher class to query AD based on a filter criteria. 您还可以使用DirectorySearcher类根据筛选条件查询AD。 This is more useful only if you would like to retrieve additional details about the user like contact, email address etc. 仅当您想要检索有关用户的其他详细信息(如联系人,电子邮件地址等)时,此功能才更有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM