Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends.
I need your one help.
if i use following ip system shows wrong information about ip location.
VB
s = Context.Request.ServerVariables("HTTP_X_FORWARDED_FOR")
       If s = "" Then
           s = Context.Request.ServerVariables("REMOTE_ADDR")
       End If

I have tried it both ; client & server side.
From Client Side it shows 127.0.0.1 and from server side it shows my ip 192.---.---.--- .
But if i try to find my ip from other sides it shows exact location with another ip.
How can i solve this problem using vb.net or c#?

I have a javascript.
If anybody help me to pass value from javascript to vb.net or c# before postback then i can solve this problem easily.

Please Help Me.
:)
Posted
Updated 9-Oct-11 7:10am
v2
Comments
RaviRanjanKr 10-Oct-11 2:56am    
hey! always use have a question or Comment at bottom of answer to give your reply. don't try to use Answer section for your Comment. :)

I have got the sollution
XML
<script type="text/javascript">
     $.getJSON("http://jsonip.appspot.com?callback=?",
    function setvar(data) {
        var a = data.ip;
        var hiddenControl = '<%= ipHide.ClientID %>';
        document.getElementById(hiddenControl).value = a;
        alert(document.getElementById(hiddenControl).value);

    });


</script>


In form tag
<input id="ipHide" type="hidden" runat="server" />
 
Share this answer
 
v2
You can use API provided by IP2Location.com. Ref at: http://www.ip2location.com/free.asp[^]
 
Share this answer
 
Comments
RaviRanjanKr 10-Oct-11 2:54am    
Comment by dreamz9 :-
I have tried IP2Location.com but i cannot store the value of IP in any variable. If i use javascript then value will be store after postback. I need that solution without page postback. Is there any other way?
RaviRanjanKr 10-Oct-11 2:55am    
Comment by dreamz9 :-
I already have database with IP Location which shows correct information but i cannot find my real ip address through asp.net.
Try

C#
using System;
using System.Web;
namespace WebApplication1
{
    public class Global : HttpApplication
    {
	protected void Application_BeginRequest(object sender, EventArgs e)
	{
	    // Get request.
	    HttpRequest request = base.Request;

	    // Get UserHostAddress property.
	    string address = request.UserHostAddress;

	    // Write to response.
	    base.Response.Write(address);

	    // Done.
	    base.CompleteRequest();
	}
    }
}


Reference Link :- ASP.NET Get IP Address (UserHostAddress)[^]
 
Share this answer
 
Your solution could not work. it is also showing my DNS which is not being helpful to find client's location.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900