beginner question: local IP-Address

G

Guest

I looked in the help but I cannot find the method to retrieve the IP-Address
of the local machine in the code behind (not the client machine, wich I can
retrieve with Request.UserHostAddress, but the IP-Address of the server where
the code behind is running).
I checked IPAddress Class but this seems not to be the correct one.
Thank you for your help
 
J

Joseph Byrns

You can do:

System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList(0).ToString
 
J

Juan T. Llibre

Request.ServerVariables("LOCAL_ADDR")

would provide the server's IP address, too.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
G

Guest

I'm not sure if this exactly what you want to do, but you can display the
account that an ASP.net page is exeuting by in Sub Page_Load
lblAccount.text = System.Security.Principal.WindowsIdentity.GetCurrent().Name
Hope this helps.

Sccr18
 
J

Juan T. Llibre

That's not what he was looking for.

He was looking for "the IP Address of the
server where the code behind is running".

re:
lblAccount.text = System.Security.Principal.WindowsIdentity.GetCurrent().Name

That should be
System.Security.Principal.WindowsIdentity.GetCurrent.Name()

I published this short file I wrote, which retrieves the
account name ASP.NET is running under, a few days ago.

Check it out...

-----------------
<%@ Page Language="VB" %>
<%@ Import NameSpace = System.Security.Principal %>
<script runat="server">
Sub Page_Load()
Dim tmp As String = WindowsIdentity.GetCurrent.Name()
Label1.Text = tmp
End Sub
</script>
<html>
<head>
<title>WindowsIdentity.GetCurrent.Name()</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
-------------




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top