0
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
Environment.UserDomainName;
properties.DomainName;
System.Web.HttpContext.Current.Request.LogonUserIdentity.Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name;

I tried above Properties in C# but no luck. It works fine on the local machine.

My Question: I have hosted a web application in abc.com domain and url is abc.com, when I access this site outside of domain or from some other external domain computers (from clients system) how to get their(clients) system domain name using c#, Jquery or Javascript.

Any solution in c#, jQuery, JS? Thanks in advance.

  • What do you mean by `no luck`? The client computer can be behind layers of networks such as Firewalls, Proxies and ISPs.. so you will get the IP of only the first point of contact from outside the network..... that will not give you the details of the user logged in to the client machine or the Domain the client machine is connected to... – Chetan Jan 17 '20 at 04:03
  • Can you explain why you need to know the logged in user details and the domain of the client network? – Chetan Jan 17 '20 at 04:04
  • I need to verify that the user is in domain or not by reading the domain from Computer properties. – Muhammad Maaz Sheikh Jan 17 '20 at 06:00

2 Answers2

0

Based on this answer about JS solution: JavaScript - How to get the name of the current user

I can add following:

  1. Browser is a kind of a sandbox, where you can't reach Win resources without user permissions.
  2. If Your user logged in to the system, then its already in your domain.
BorHunter
  • 893
  • 3
  • 18
  • 44
  • Is there any solution in c# .net that gives domain of client user ? – Muhammad Maaz Sheikh Jan 17 '20 at 07:16
  • By default, ASP.NET impersonation is disabled. If you enable impersonation, your ASP.NET application runs under the security context of the user authenticated. You can enable in Windows Authentication in IIS, impersonation on. To take data use the following code: https://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net/ – BorHunter Jan 17 '20 at 09:03
0

try like this ,By this way you will get Hostname

string ipAddress = Request.UserHostAddress;
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
string domainName = entry.HostName;

and for computer name you can do like this
var comutername=  HttpContext.Current.Server.MachineName 

and in your javascript you will get computer name by using ActiveXObject as

function GetClientInfo() {
        var net = new ActiveXObject("wscript.network");
        alert("Computer Name : " + net.ComputerName + "\n User Name : " + net.UserName + "\n Domain Name :"
            + net.UserDomain);

    }
Ishwar Gagare
  • 723
  • 3
  • 9
  • @MuhammadMaazSheikh,yes ...but you can get the Domain and computer name in c# and passed that into your javascript through ajax..right.. – Ishwar Gagare Jan 17 '20 at 13:10
  • i already mentioned that i get correct domain and computer name on local deployment within the same domain but when i deployed my application in different domain then c# not able to return client domain who is accessing the Application. – Muhammad Maaz Sheikh Jan 18 '20 at 06:52