Exemple #1
0
        /// <summary>
        /// Gets an object that represents the current client
        /// connected to the application in the current request.
        /// </summary>
        public ClientConnectionInfo GetConnectionInfo()
        {
            var context = _httpContextAccessor.HttpContext;

            var info = new ClientConnectionInfo();

            if (context != null && context.Request != null)
            {
                info.IPAddress = context?.Connection?.RemoteIpAddress?.ToString();
                info.UserAgent = context.Request?.Headers?.GetOrDefault("User-Agent");
            }

            return(info);
        }
        public ClientConnectionInfo GetConnectionInfo()
        {
            var info = new ClientConnectionInfo();

            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                var request = HttpContext.Current.Request;

                info.IPAddress = GetIPAddress(request);
                info.UserAgent = request.UserAgent;
            }

            return(info);
        }