【发布时间】:2019-01-30 01:23:46
【问题描述】:
我支持需要获取客户端计算机名称的系统我尝试了不同的代码,但所有代码都只获取主机服务器的计算机名称,而不是客户端的计算机名称。这是sn-p:
public void CreateEvents(string className, string eventName, string eventData, string userId)
{
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
string compname= HttpContext.Current.Request.UserHostAddress;
var browser = HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version;
if (string.IsNullOrEmpty(userId))
{
userId = compname;
}
var entity = new EventLog
{
ClassName = className,
EventName = eventName,
EventData = eventData,
IpAddress = ipAddress,
Browser = browser,
UserId = userId,
CreatedDate = DateTime.Now
};
_db.EventLogs.Add(entity);
_db.SaveChanges();
}
public string GetIpAddress()
{
HttpContext context = System.Web.HttpContext.Current;
string compname= context.Request.UserHostAddress; //System.Net.Dns.GetHostName();
return compname;
}
提前致谢!
【问题讨论】:
-
服务器和客户端浏览器在同一个网络?
标签: c# asp.net-mvc