How to register IP address and computer name in ASP.net

I am developing a web application in ASP.net that requires a username and password.

I want to register the IP address and machine name of the client that access this web application.

I am using log4net for logging.

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

Login Page Page_Load Method:

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

Changes in Web.Config:

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

Its a really huge project, so please offer me a method that requires minimal changes in the code to register the IP address and name of the Client's machine.

+4
source share
4 answers

Have you tried to use the following?

Request.UserHostAddress

Request.UserHostName

,

IP- ?

+15

Try .

string[] computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName.Split(new Char[] { '.' });
  String ecname = System.Environment.MachineName;
            txtComputerName.Text = computer_name[0].ToString();

IP- ..

Request.ServerVariables["REMOTE_ADDR"]

... fooobar.com/questions/102978/...

+5
Dns.GetHostEntry(log.IPAddress).HostName

- . ...

0

.. ,

0

All Articles