コード例 #1
0
        private bool IsRequestAuthorized()
        {
            var isLocalhost  = Request.ServerVariables["SERVER_NAME"] == "localhost";
            var isTestServer = Request.ServerVariables["SERVER_NAME"] == ConfigurationManager.AppSettings["testServer"];

            string clientIpAddr = string.Empty;

            if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                clientIpAddr = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(':').First();
            }
            else if (Request.UserHostAddress.Length != 0)
            {
                clientIpAddr = Request.UserHostAddress.Split(':').First();
            }

            var allowedIp = ConfigurationManager.AppSettings["cronServerIpAddress"];
            var res       = isLocalhost || isTestServer || (!String.IsNullOrWhiteSpace(allowedIp) && clientIpAddr == allowedIp);

            if (!res)
            {
                _umbraco.LogWarn <SystemSurfaceController>("Denied access to system APIs for IP: " + clientIpAddr);
            }

            return(res);
        }