Пример #1
0
        public async Task <IActionResult> Index()
        {
            ViewData["Message"]          = "Esta es una app de .NET Core y Docker... Mola!!";
            ViewData["SistemaOperativo"] = String.Concat("El sistema operativo: ", System.Runtime.InteropServices.RuntimeInformation.OSDescription);
            ViewData["IdContenedor"]     = String.Concat("La máquina / contenedor: ", System.Environment.MachineName);

            try
            {
                IPGeographicalLocation model = await IPGeographicalLocation.QueryGeographicalLocationAsync(Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString());

                if (String.IsNullOrEmpty(model.CountryName))
                {
                    ViewData["Location"] = "El pais y ciudad: Recuerda que en localhost esto no va.";
                }
                else
                {
                    ViewData["Location"] = String.Format("El país y ciudad: {0}, {1}", model.CountryName, model.City);
                }
            }
            catch (Exception)
            {
                ViewData["Location"] = "El pais y ciudad: Va a ser que ahora no.";
            }


            return(View());
        }
Пример #2
0
        public async Task <IActionResult> Index(string ip)
        {
            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
            }
            IPGeographicalLocation model = await IPGeographicalLocation.QueryGeographicalLocationAsync(ip);

            return(View(model));
        }
Пример #3
0
        private async Task <string> GetCurrentCountryCode()
        {
            var ip = CommonHelper.GetIp(Request);

            Console.WriteLine(ip);
            // ip = "27.72.89.106";
            if (string.IsNullOrEmpty(ip))
            {
                return(null);
            }
            var location = await IPGeographicalLocation.QueryGeographicalLocationAsync(ip);

            return(location?.CountryCode);
        }
        private async Task <string> GetCurrentCountryCode()
        {
            try
            {
                var ip = CommonHelper.GetIp(Request);
                Console.WriteLine(ip);
                ip = "27.72.89.106";
                if (string.IsNullOrEmpty(ip))
                {
                    return(null);
                }
                var location = await IPGeographicalLocation.QueryGeographicalLocationAsync(ip);

                return(location?.CountryCode);
            }
            catch (Exception e)
            {
                Logger.LogError("SecurityController ==>> GetCurrentCountryCode: " + e.Message);
                return("VI");
            }
        }