Click here to Skip to main content
12,882,493 members (27,720 online)
Rate this:
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 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 or c#?

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

Please Help Me.
Posted 9-Oct-11 7:09am
Updated 9-Oct-11 7:10am
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. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

I have got the sollution
<script type="text/javascript">
    function setvar(data) {
        var a = data.ip;
        var hiddenControl = '<%= ipHide.ClientID %>';
        document.getElementById(hiddenControl).value = a;


In form tag
<input id="ipHide" type="hidden" runat="server" />
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use API provided by Ref at:[^]
RaviRanjankr 10-Oct-11 2:54am
Comment by dreamz9 :-
I have tried 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
Rate this: bad
Please Sign up or sign in to vote.

Solution 4


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.
	    // Done.

Reference Link :- ASP.NET Get IP Address (UserHostAddress)[^]
Rate this: bad
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 10 Oct 2011
Copyright © CodeProject, 1999-2017
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