如何使用c#或jQuery或Javascript获取客户端系统/ PC域和PC名称

问题描述 投票:0回答:2
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
Environment.UserDomainName;
properties.DomainName;
System.Web.HttpContext.Current.Request.LogonUserIdentity.Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name;

我在C#的Properties上面尝试过,但是没有运气。它在本地计算机上工作正常。

我的问题:我在abc.com域中托管了一个Web应用程序,并且当我在域外部或从其他外部域计算机(从客户端系统)访问此站点时,URL为abc.com如何使用c#获取其(客户端)系统域名,Jquery或Javascript。

使用C#,jQuery,JS的任何解决方案?预先感谢。

javascript c# jquery .net asp.net-mvc
2个回答
0
投票

基于关于JS解决方案的以下答案:JavaScript - How to get the name of the current user

我可以添加以下内容:

  1. 浏览器是一种沙箱,没有用户权限就无法访问Win资源。
  2. 如果您的用户登录到系统,则它已经在您的域中。

0
投票

尝试这样,这样您将获得主机名

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 

并且在您的JavaScript中,您将通过使用ActiveXObject作为获得计算机名称

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

    }
© www.soinside.com 2019 - 2024. All rights reserved.