需要获取计算机名称在IIS上托管站点时 [英] Need to get Computer name When site hosted on IIS
本文介绍了需要获取计算机名称在IIS上托管站点时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在我的网站托管在iis服务器上时获取计算机名称。
当我从本地运行我的网站时,我将获得用户名。这是我的代码。
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userp = UserPrincipal.Current;
但是当我在iis服务器上发布我的网站时我没有得到系统名称
i would like to get the computer name when my site is hosted on iis server.
i will get the username when i running my site from local. here is my code.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userp = UserPrincipal.Current;
but when i publish my site on iis server i m not getting the system name
推荐答案
尝试任何一个来自下面
Try any one from below
System.Environment.MachineName
or
SystemInformation.ComputerName
or
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
or
String hostName = Dns.GetHostName();
链接可以帮助获取客户端计算机名称
这篇关于需要获取计算机名称在IIS上托管站点时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文