简体   繁体   中英

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

Assume there is Active Directory domain: " chiled.root.f1dm.com "

Netbios name: " 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). 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

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). Thanks!

If your user as logged in his using AD, you can try to get his name via ServerVariables. Exemple:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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