コード例 #1
0
        public static bool RouteAreaNameIs(this RouteData route, string name)
        {
            var check = route.RouteGetAreaName();
            var ret   = StringUtilities.AreEqualCaseInsensitive(check, name);

            return(ret);
        }
コード例 #2
0
            public override void Write(byte[] buffer, int offset, int count)
            {
                var isTextHtml = false;

                try
                {
                    // We need to optimize only html. Applying optimization to any file download will curropt the file
                    isTextHtml = StringUtilities.AreEqualCaseInsensitive(HttpContext.Current.Response.ContentType, System.Net.Mime.MediaTypeNames.Text.Html);
                }
                catch { }

                if (isTextHtml)
                {
                    // capture the data and convert to string
                    byte[] data = new byte[count];
                    Buffer.BlockCopy(buffer, offset, data, 0, count);
                    string s = Encoding.Default.GetString(buffer);

                    // filter the string
                    StringBuilder sb = new StringBuilder();
                    using (StringReader sr = new StringReader(s))
                    {
                        while (true)
                        {
                            var line = sr.ReadLine();

                            if (line != null)
                            {
                                line = line.TrimStart();

                                if (!string.IsNullOrWhiteSpace(line))
                                {
                                    sb.AppendLine(line);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    s = sb.ToString().TrimEnd("\r\n".ToCharArray());

                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        // write the data to stream
                        byte[] outdata = Encoding.Default.GetBytes(s);
                        actualStream.Write(outdata, 0, outdata.GetLength(0));
                    }
                }
                else
                {
                    actualStream.Write(buffer, 0, count);
                }
            }
コード例 #3
0
        public void Validate(string uid, string time, string digest)
        {
            if (string.IsNullOrWhiteSpace(AuthKey))
            {
                throw new AuthenticationException("Missing Auth Key in configuration file");
            }
            if (string.IsNullOrWhiteSpace(uid))
            {
                throw new AuthenticationException("Argument cannot be null or empty: uid");
            }
            if (string.IsNullOrWhiteSpace(time))
            {
                throw new AuthenticationException("Argument cannot be null or empty: time");
            }
            if (string.IsNullOrWhiteSpace(digest))
            {
                throw new AuthenticationException("Argument cannot be null or empty: digest");
            }

            var hashMD52  = new MD5CryptoServiceProvider();
            var sPassword = uid + time + AuthKey;

            var pwdHash2 = hashMD52.ComputeHash(System.Text.Encoding.Default.GetBytes(sPassword));
            var hexStr   = string.Empty;

            for (int x = 0; x < pwdHash2.Length; x++)
            {
                var hexChar = Hex(pwdHash2[x]);

                if (hexChar.Length == 1)
                {
                    hexStr += "0";
                }
                hexStr += hexChar;
            }

            if (!StringUtilities.AreEqualCaseInsensitive(digest, hexStr))
            {
                throw new AuthenticationException("Authorization Error");
            }
        }
        protected AjaxContentTypes AjaxIdentifyContentType(ExceptionContext filterContext)
        {
            AjaxContentTypes ret = AjaxContentTypes.Text;
            var acceptTypes      = filterContext.HttpContext.Request.AcceptTypes;

            if (acceptTypes.Any(t => StringUtilities.AreEqualCaseInsensitive(t, "text/plain")))
            {
                ret = AjaxContentTypes.Text;
            }
            else if (acceptTypes.Any(t => StringUtilities.AreEqualCaseInsensitive(t, "text/html")))
            {
                ret = AjaxContentTypes.Html;
            }
            else if (acceptTypes.Any(t => StringUtilities.AreEqualCaseInsensitive(t, "application/json")))
            {
                ret = AjaxContentTypes.Json;
            }
            else if (acceptTypes.Any(t => StringUtilities.AreEqualCaseInsensitive(t, "application/xml")))
            {
                ret = AjaxContentTypes.Xml;
            }

            return(ret);
        }