本文介绍了通过WCF将Windows凭据从客户端传递到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望将客户端Windows凭据传递给WCF服务,一旦通过身份验证,我想将相同的客户端Windows凭据传递给数据库以进行进一步的操作.我该如何实现,请帮助我.预先感谢
I want to pass Client Windows credentials to WCF service, once its authenticated I want to pass same Client Windows credentials to Database for further operation. How can I achieve please help me. Thanks in advance
推荐答案
WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal user = new WindowsPrincipal(ident);
using (DirectoryEntry de = new DirectoryEntry("LDAP://" + user.Identity.Name))
{
using (DirectorySearcher adSearch = new DirectorySearcher(de))
{
adSearch.Filter = "(sAMAccountName=" + username + ")";
SearchResult adSearchResult = adSearch.FindOne();
UserCredentials.CommitID = user.Identity.Name;
UserCredentials.UserName = StripLoggedUserName(adSearchResult.Path);
UserCredentials.LoginUserName = StripLoggedUserName(adSearchResult.Path);
UserCredentials.LoginUserCommitID = user.Identity.Name;
}
}
这篇关于通过WCF将Windows凭据从客户端传递到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!