Esempio n. 1
0
        public string GenerateUrlBase(HttpRequest httpRequest)
        {
            var sb = new StringBuilder();
            sb.Append(!httpRequest.UsesSsl ? "http" : "https");
            sb.Append("://");
            sb.Append(httpRequest.ServerDomain);

            if ((!httpRequest.UsesSsl && httpRequest.Port == 80) ||
                (httpRequest.UsesSsl && httpRequest.Port == 443))
            {
                return sb.ToString();
            }

            sb.Append(":");
            sb.Append(httpRequest.Port);

            return sb.ToString();
        }
Esempio n. 2
0
        public bool ValidateCookie(HttpRequest httpRequest, HeaderCookie headerCookie)
        {
            if (headerCookie.Secure != null && headerCookie.Secure == true && httpRequest.UsesSsl == false)
            {
                return false;
            }
            if (headerCookie.Path != null && httpRequest.Path.StartsWith(headerCookie.Path) == false)
            {
                return false;
            }

            if (headerCookie.Expires != null && DateTimeOffset.Now > headerCookie.Expires)
            {
                return false;
            }

            if (headerCookie.Domain == null) return true;

            var cookieHosts = headerCookie.Domain.Split('.');
            var requestHosts = httpRequest.ServerDomain.Split('.');
            var ok = true;
            for (var i = cookieHosts.Length; i >= 0; i--)
            {
                var cookieHost = cookieHosts[i];
                if (cookieHost == "*")
                {
                    break;
                }
                if (requestHosts.Length - 1 < i)
                {
                    ok = false;
                    break;
                }
                var requestHost = requestHosts[i];
                if (requestHost == cookieHost) continue;
                ok = false;
                break;
            }
            return ok;
        }