如何登录ASP.net客户端IP地址和机器名 [英] How to log Client IP Address and Machine Name in ASP.net

查看:326
本文介绍了如何登录ASP.net客户端IP地址和机器名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发在ASP.net Web应用程序,这需要登录名和密码。

I am developing a Web Application in ASP.net, which requires login name and password.

我要记录IP地址和客户端的计算机名称,谁正在访问该Web应用程序。

I want to log IP Address and Machine Name of client, who are accessing this Web Application.

我使用log4net的日志记录。

I am using log4net for logging.

我已经试过这件作品code,但我部署使用IIS-7,而不是客户端计算机名称此Web应用程序后获取服务器主机名机日志。

I have tried this piece of code, but I am getting Server Machine HostName in log after deploying this web application using IIS-7 instead of Client Machine Name.

登录页面的Page_Load 方法:

protected void Page_Load(object sender, EventArgs e)
{
    log4net.GlobalContext.Properties["Hostname"] = Dns.GetHostName();
}

Web.Config中的变化:

Web.Config Changes:

 <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %property{Hostname} [%thread] %-5level %logger - %message%newline" />
 </layout>

它真正庞大的系统工程,所以,请给我建议这需要code最小更改记录IP地址的客户端的计算机名称和方式。

Its really huge project, So Please suggest me the way which requires minimum changes in Code to log the IP Address and Machine Name of Client.

推荐答案

你有没有尝试使用以下?

Did you try using following?

Request.UserHostAddress

Request.UserHostName

请参考贴在不同的线程以下的答案

Refer to following answer posted on a different thread

获取客户端的IP地址,计算机名?

这篇关于如何登录ASP.net客户端IP地址和机器名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆