检测使用ASP.NET应用登录电脑的用户我想开发一个ASP.NET应用,可以检测登录的用户进入窗口域。这些凭据将用于登录到ASP.NET应用程序。我怎样才能做到这一点?谢谢!在IIS中,启用集成Windows身份验证,在代码中,如果您使用:Request.ServerVariables["LOGON_USER"],它将返回登录用户的Windows用户名,即MYDOMAINMYUSERNAME对于ASP.net,您可以使用HttpContext。Current.User.Identity如果IIS配置正确(至少没有匿名登录),这是我使用系统对ActiveDirectory进行身份验证的C#代码;使用System.DirectoryServices;namespaceXYZcompany.Enterprise{publicclassAuthenticationMgr{privatestaticreadonlyintAD_ERR_LOGON_FAIL=-2147023570;privatestaticreadonlystring_path="LDAP://xxx.yyy.ggg";privatestaticreadonlystring_domain="xxx.yyy.ggg";publicstaticboolIsAuthenticated(stringusername,stringpwd){boolauthenticatedFlag=true;stringdomainAndUsername=_domain+"\"+用户名;DirectoryEntryentry=newDirectoryEntry(_path,domainAndUsername,pwd);try{//绑定到本机AdsObject以强制进行身份验证。对象obj=entry.NativeObject;DirectorySearchersearch=newDirectorySearcher(入口);搜索。Filter="(SAMCountName="+username+")";search.PropertiesToLoad.Add("cn");SearchResultresult=search.FindOne();if(result==null){authenticatedFlag=false;}else{authenticatedFlag=true;}}catch(System.Runtime.InteropServices.COMExceptionex){if(ex.ErrorCode==AD_ERR_LOGON_FAIL){authenticatedFlag=false;}else{thrownewApplicationException("由于系统错误无法验证用户。",ex);}你应该看看ActiveDirectoryMembershipProviderit'sbuiltintoASP.NET.That'sallforC#LearningTutorial:DetectingUsersLoggedintoaComputerUsinganASP.NETApplication很有用,需要进一步了解C#学习教程,希望大家多多关注——System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString本文收集自网络,不代表立场,如涉及侵权,请点击有权联系管理员删除,如需转载请注明出处: