How to get data from the Client Side to the Server

0

Hello.

Developed an application in .NET CORE and the access page will pick up the geolocation of the client with the coordinates of Longitude and Latitude. However, I made this code using javascript, and the same will run on the client side, I made an implement to fill 2 Label with the information, but I am not able to send these to my server, my idea and store the location (With the knowledge of the client), but this is not working, I can not do that.

Below the javascript that I'm getting the location, and in the sequence as the label inside my html, I did not put it all but it's inside a form, I am.

Javascript

<script>
    var x = document.getElementById("lat");
    var y = document.getElementById("lot");

    function getLocation()
    {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else { 

            y.innerHTML = "Geolocation is not supported by this browser.";
        }
    }

    function showPosition(position) {
        x.textContent = "Latitude: " + position.coords.latitude;
        y.innerHTML = "Longitude: " + position.coords.longitude;
        <%--Codigo para pegar as cordenadas e setar as mesmas nas Labels --%>
        $("#lblat").text("Latitude: " + position.coords.latitude);
        //$("#lblog").text("Longitude: " + position.coords.longitude);
        $("#lblog").text("Longitude: " +position.coords.longitude);
        $("#endereco").text("Longitude: " +position.coords.longitude);
    }


    $(document).ready(function carregar() {
        getLocation();
        showPosition();
    });
</script>

HTML

<div class="container">
    <div class="col">
        <div class="row">
            <hr />
            <asp:Label ID="Label1" runat="server" Text="Controle de Acesso "></asp:Label>
             <br />
            <asp:Label ID="lblat" runat="server" > </asp:Label>
            <br />
            <asp:Label ID="lblog" runat="server" Text=""> </asp:Label>
            <br />
            <asp:Label ID="lbIp" runat="server" Text=""></asp:Label>
            <br />
            <asp:Label ID="lbHost" runat="server" Text=""></asp:Label>
            <br />
             <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
            <br />
             <asp:Label ID="lboutro" runat="server" Text=""></asp:Label>
            <hr />
            <br />
            <br />
             <asp:Label ID="lat" runat="server" Text=""></asp:Label>
               <br />
             <asp:Label ID="lot" runat="server" Text=""></asp:Label>
            <br />
        </div>
    </div>
</div>

Below a print of my application picking up the information, I want to get them to store in a database and use this to compare the client access places, and if I have some access in a different place, p>

    
asked by anonymous 30.09.2018 / 01:30

1 answer

0

In order to send the client information to the server, I recommend using ajax since it is working with javascript and also does not need client interaction. The .Net Core does not work with the "Runat = Server" syntax.

This documentation makes it very clear how to do the procedure:

01.10.2018 / 20:33