简体   繁体   English

C# - Windows身份验证 - 如何从HttpContext用户获取Full doMain名称(FQDN)

[英]C# - Windows authentication - How to get from HttpContext user's Full doMain name (FQDN)

Assume there is Active Directory domain: " chiled.root.f1dm.com " 假设有Active Directory域:“ chiled.root.f1dm.com

Netbios name: " CHILED1F1 " Netbios名称:“ CHILED1F1

Given this code: 鉴于此代码:

if (HttpContext.Current == null || HttpContext.Current.User == null ||
            !HttpContext.Current.User.Identity.IsAuthenticated)
        {
            throw new MyException(WRONG_USERNAME_OR_PASSWORD_ERROR_CODE, WRONG_USERNAME_OR_PASSWORD_ERROR_MESSAGE);
        }

I'm looking for a way to reach from the HttpContext the user's Fully qualified domain name (FQDN). 我正在寻找一种从HttpContext到达用户的完全限定域名(FQDN)的方法。 Currently I'm getting from the context the user's domain in the Netbios form (Like: CHILED1F1\\user_name) but I need this: chiled.root.f1dm.com\\user_name 目前我从Netbios表单中获取用户域的上下文(如:CHILED1F1 \\ user_name)但我需要这个: chiled.root.f1dm.com \\ user_name

I there a way to do it? 我有办法做到吗? I need it for the Windows current user only (So the Machine's domain name will not help me). 我只需要Windows当前用户(因此机器的域名对我没用)。 Thanks! 谢谢!

If your user as logged in his using AD, you can try to get his name via ServerVariables. 如果您的用户登录使用AD,您可以尝试通过ServerVariables获取他的名字。 Exemple: 例:

string username = Request.ServerVariables["AUTH_USER"].ToString();

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

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