user3264676 user3264676 - 8 months ago 152
ASP.NET (C#) Question

How to log Client IP Address and Machine Name in

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

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

I am using log4net for logging.

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.

Login Page Page_Load

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

Web.Config Changes:

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

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.

Sam Sam

Did you try using following?



Refer to following answer posted on a different thread

Get client's IP address and computer name?