Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0 ASP.NET
Hello Friends.
I need your one help.
if i use following ip system shows wrong information about ip location.
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.
Smile | :)
Posted 9-Oct-11 8:09am
dreamz9814
Edited 9-Oct-11 8:10am
v2
Comments
RaviRanjankr at 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. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

I have got the sollution
<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" />
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use API provided by IP2Location.com. Ref at: http://www.ip2location.com/free.asp[^]
  Permalink  
Comments
RaviRanjankr at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try
 
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)[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Your solution could not work. it is also showing my DNS which is not being helpful to find client's location.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,205
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,474


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 10 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100