Can anybody tell me how to get servers domain name in asp.net? (Environment.UserDomainName
returns "IIS APPPOOL" string)
Thanks for replays, but mostly they are about DNS name of the server, what I need is the domain name. For example when I login via windows authentication I type domain\user and I need this "domain"
A bit late.. But the missing and best answer I have found, after having exactly the same issue:
private static string getComputerDomain()
{
try
{
return Domain.GetComputerDomain().Name;
}
catch (ActiveDirectoryObjectNotFoundException)
{
return "Local (No domain)";
}
}
As stated on the msdn site:
This return value is independent of the domain credentials under which the application is run. This method will retrieve the computer's domain regardless of the trusted account domain credentials it is run under.
Tested on my personal pc (no AD-domain) and at work (with AD-domain) under IIS (anonymous access).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With