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.
 
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>
-------------
 
Joined
Dec 6, 2006
Messages
2
Reaction score
0
Hi guys,

one more thing to talk about getting the local address.

doing this:
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0]

you get the correct ip

doing this way:

HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];

you get the 127.0.0.1, that´s not wrong, but doent help so much

I hope it helps. regards
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top