How to get details of site visitor in asp.net c#

As we have seen previously Geolocation to showcurrent location with Google Maps API . In this article, we learn how to get visitor detail like country, state, city, IP address, latitude and longitude.


Source Code:-
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Get Current Location  Details</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
        $.getJSON('https://geoip-db.com/json/geoip.php?jsonp=?')
           .done(function (location) {
               $('#country').html(location.country_name);
               $('#state').html(location.state);
               $('#city').html(location.city);
               $('#latitude').html(location.latitude);
               $('#longitude').html(location.longitude);
               $('#ip').html(location.IPv4);
           });
    </script>
</head>
<body>
    <form runat="server" id="frm1">
        <fieldset style="width: 350px;">
            <legend>Get Current Location  Details</legend>
            <div>
                Country:
                <asp:Label runat="server" ID="country"></asp:Label>
            </div>
            <div>
                State:
                <asp:Label runat="server" ID="state"></asp:Label>
            </div>
            <div>City:
                <asp:Label runat="server" ID="city"></asp:Label></div>
            <div>Latitude:
                <asp:Label runat="server" ID="latitude"></asp:Label></div>
            <div>Longitude:
                <asp:Label runat="server" ID="longitude"></asp:Label></div>
            <div>IP: <asp:Label runat="server" ID="ip"></asp:Label></div>
        </fieldset>
    </form>

</body>
</html>



Note: On page load browser asks you for access your location so once you need to allow it.
How to get details of site visitor in asp.net c# How to get details of site visitor in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 4:41:00 PM Rating: 5

No comments:

Powered by Blogger.