Beispiel #1
0
        /// <summary>
        /// Parses the request from the TcpClient
        /// </summary>
        public void ParseRequest()
        {
            var request = TcpClient.ReadLine();
            var tokens  = request.Split(' ');

            if (tokens.Length != 3)
            {
                throw new Exception("invalid http request line");
            }

            Method  = tokens[0].ToUpper();
            FullUrl = tokens[1];
            var parts = FullUrl.Split('?');

            if (parts.Length == 1)
            {
                UrlParameters = new Dictionary <string, string>();
            }
            else
            {
                var all = string.Join("?", parts.Skip(1));
                UrlParameters = EncodedStringToDictionary(all);
            }

            Path     = parts.First();
            Protocol = tokens[2];
        }
Beispiel #2
0
        /// <summary>
        /// 生成多级栏目链接
        /// </summary>
        /// <param name="separator"></param>
        /// <returns></returns>
        public string BuildLinkHtml(string separator)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(FullPath) && !string.IsNullOrEmpty(FullUrl))
            {
                string[] urls    = FullUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string[] names   = FullPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string   longUrl = "/";
                for (int i = 0; i < names.Length; i++)
                {
                    if (i < urls.Length)
                    {
                        sb.Append(string.Format("<a href='{0}'>{1}</a>", longUrl + urls[i] + "/", names[i]));
                        sb.Append(separator);
                        longUrl += urls[i] + "/";
                    }
                }
                sb.Remove(sb.Length - separator.Length, separator.Length);
            }
            return(sb.ToString());
        }