Beispiel #1
0
        private static UrlParts CreateForRelativePath(IServerUtility serverUtility, string url)
        {
            var    path     = url;
            string qs       = null;
            string pathInfo = null;

            var queryStringStartIndex = url.IndexOf('?');

            if (queryStringStartIndex != -1)
            {
                qs   = url.Substring(queryStringStartIndex);
                path = url.Substring(0, queryStringStartIndex);
            }

            var fileExtIndex = path.IndexOf('.');

            if (fileExtIndex != -1)
            {
                var pathInfoStartIndex = path.IndexOf('/', fileExtIndex);

                if (pathInfoStartIndex != -1)
                {
                    pathInfo = path.Substring(pathInfoStartIndex);
                    path     = path.Substring(0, pathInfoStartIndex);
                }
            }

            var parts = new UrlParts(serverUtility, path);

            parts.SetQueryString(qs);
            parts.PathInfoDict.Parse(pathInfo);

            return(parts);
        }
		public void BuildPathWithPathInfoAndQueryString()
		{
			UrlParts builder = new UrlParts("controller", "action");
			builder.PathInfoDict["State"] = "FL";
			builder.SetQueryString("type=Residential");

			Assert.AreEqual("controller/action/State/FL?type=Residential", builder.BuildPath());
		}
Beispiel #3
0
        /// <summary>
        /// Appends the query string.
        /// </summary>
        /// <param name="parts">The parts.</param>
        /// <param name="parameters">The parameters.</param>
        protected virtual void AppendQueryString(UrlParts parts, UrlBuilderParameters parameters)
        {
            var queryString = parameters.QueryString;

            var suffix = string.Empty;

            if (queryString != null)
            {
                if (queryString is IDictionary)
                {
                    var qsDictionary = (IDictionary)queryString;

                    suffix = CommonUtils.BuildQueryString(serverUtil, qsDictionary, false);
                }
                else if (queryString is NameValueCollection)
                {
                    suffix = CommonUtils.BuildQueryString(serverUtil, (NameValueCollection)queryString, false);
                }
                else if (queryString is string && ((string)queryString).Length > 0)
                {
                    var pairs = queryString.ToString().Split('&');

                    suffix = string.Empty;

                    foreach (var pair in pairs)
                    {
                        var keyvalues = pair.Split(new[] { '=' }, 2);

                        if (keyvalues.Length < 2)
                        {
                            continue;
                        }

                        if (suffix.Length != 0)
                        {
                            suffix += "&";
                        }

                        suffix += serverUtil.UrlEncode(keyvalues[0]) + "=" + serverUtil.UrlEncode(keyvalues[1]);
                    }
                }
            }

            if (suffix != string.Empty)
            {
                parts.SetQueryString(suffix);
            }
        }
Beispiel #4
0
        private static UrlParts CreateForAbsolutePath(IServerUtility serverUtility, Uri uri)
        {
            var host = uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.Length - uri.PathAndQuery.Length);

            var parts = new UrlParts(serverUtility, host);

            foreach (var segment in uri.Segments)
            {
                parts.AppendPath(segment);
            }

            parts.ConvertPathInfoToDict();
            parts.SetQueryString(uri.Query);

            return(parts);
        }
		public void QueryStringCanHandleDuplicatedEntries()
		{
			UrlParts builder = new UrlParts("home/index.ext");

			builder.SetQueryString("City=SP&State=MD&State=NY");

			Assert.AreEqual("home/index.ext?City=SP&State=MD&State=NY", builder.BuildPath());
		}
		public void QueryStringIsExtractedAndParsed()
		{
			UrlParts builder = new UrlParts("home/index.ext");

			builder.SetQueryString("City=SP&State=MD");

			builder.QueryString["type"] = "home";

			Assert.AreEqual("home/index.ext?City=SP&State=MD&type=home", builder.BuildPath());
		}
Beispiel #7
0
		private static UrlParts CreateForAbsolutePath(Uri uri)
		{
			string host = uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.Length - uri.PathAndQuery.Length);

			UrlParts parts = new UrlParts(host);

			foreach (string segment in uri.Segments)
			{
				parts.AppendPath(segment);
			}

			parts.ConvertPathInfoToDict();
			parts.SetQueryString(uri.Query);

			return parts;
		}
Beispiel #8
0
		private static UrlParts CreateForRelativePath(string url)
		{
			string path = url;
			string qs = null;
			string pathInfo = null;

			int queryStringStartIndex = url.IndexOf('?');
			int fileExtIndex = url.IndexOf('.');

			if (queryStringStartIndex != -1)
			{
				qs = url.Substring(queryStringStartIndex);
				path = url.Substring(0, queryStringStartIndex);
			}

			if (fileExtIndex != -1)
			{
				int pathInfoStartIndex = path.IndexOf('/', fileExtIndex);

				if (pathInfoStartIndex != -1)
				{
					pathInfo = path.Substring(pathInfoStartIndex);
					path = path.Substring(0, pathInfoStartIndex);
				}
			}

			UrlParts parts = new UrlParts(path);
			parts.SetQueryString(qs);
			parts.PathInfoDict.Parse(pathInfo);

			return parts;
		}
		private static UrlParts CreateForAbsolutePath(IServerUtility serverUtility, Uri uri)
		{
			var host = uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.Length - uri.PathAndQuery.Length);

			var parts = new UrlParts(serverUtility, host);

			foreach (var segment in uri.Segments)
			{
				parts.AppendPath(segment);
			}

			parts.ConvertPathInfoToDict();
			parts.SetQueryString(uri.Query);

			return parts;
		}
		private static UrlParts CreateForRelativePath(IServerUtility serverUtility, string url)
		{
			var path = url;
			string qs = null;
			string pathInfo = null;

			var queryStringStartIndex = url.IndexOf('?');

			if (queryStringStartIndex != -1)
			{
				qs = url.Substring(queryStringStartIndex);
				path = url.Substring(0, queryStringStartIndex);
			}

			var fileExtIndex = path.IndexOf('.');

			if (fileExtIndex != -1)
			{
				var pathInfoStartIndex = path.IndexOf('/', fileExtIndex);

				if (pathInfoStartIndex != -1)
				{
					pathInfo = path.Substring(pathInfoStartIndex);
					path = path.Substring(0, pathInfoStartIndex);
				}
			}

			var parts = new UrlParts(serverUtility, path);
			parts.SetQueryString(qs);
			parts.PathInfoDict.Parse(pathInfo);

			return parts;
		}