Solved

IP address of client from MVC ASP.net application

Posted on 2013-12-03
3
1,067 Views
Last Modified: 2013-12-08
What is the best foolproof way of getting client IP address for the client who is behind firewall, proxy or load balancer in ASP.net to harden the security of the site?
0
Comment
Question by:Jugnoo2013
  • 2
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39693324
If this is on the public internet, the only thing you can get is their public IP address.  It's reported in the server variables under REMOTE_ADDR.

This simple program reports all the server variables available on your server.  REMOTE_ADDR is added separately at the bottom.
<%@ Page Language = "VBScript" AspCompat="True" %>
<% Response.Buffer = true %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>ASPX .NET Server Variables</title>
</head>
<body>
<h1 align="center">ASPX .NET Server Variables</h1>
<%
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables 
' Get names of all keys into a string array.
arr1 = coll.AllKeys 
For loop1 = 0 To arr1.GetUpperBound(0)
   Response.Write("<b>" & arr1(loop1) & "</b>: ")
   arr2 = coll.GetValues(loop1) ' Get all values under this key.
   For loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1

Response.Write ("<br>" & vbCrLf)
Response.Write ("REMOTE_ADDR" & ": " _
	& Request.ServerVariables("REMOTE_ADDR") _
	& "<br>" & vbCrLf)

%>

</body>
</html>

Open in new window

0
 

Author Comment

by:Jugnoo2013
ID: 39693357
Thanks, I will take a look. Does same hold true for intranet sites?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39693399
Intranet clients will show their intranet IPs as long as there is no proxy in between you and them.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now