예제 #1
0
파일: ViewsPage.cs 프로젝트: rakale/MyShop
        protected internal Uri createUri(int i)
        {
            var uri = CreateUrl.ToString();

            uri += $"&switchOfCreate={i}";

            return(new Uri(uri, UriKind.Relative));
        }
예제 #2
0
        /// <summary>
        /// Returns a new url that will replace, or add a parameter
        /// to the one that is currently being used.
        /// </summary>
        /// <param name="absoluteUrl">The root url to add parameters too.</param>
        /// <param name="parameters">Existing list of parameters to be altered.</param>
        /// <param name="key">A parameter key not to be removed from the list of parameters.</param>
        /// <returns>A new url containing the parameters provided and the new key and value.</returns>
        protected virtual string GetNewUrl(string absoluteUrl, NameValueCollection parameters, string key)
        {
            List <string> list = new List <string>();

            // keys beginning with an _ will not be added to links, unless it was in the parameter.
            if (parameters != null)
            {
                foreach (string index in parameters.Keys)
                {
                    if (index != null &&
                        (index.StartsWith("_") == false || index.Equals(key)))
                    {
                        if (parameters[index] != null)
                        {
                            list.Add(String.Format("{0}={1}", index, HttpUtility.UrlEncode(parameters[index])));
                        }
                        else
                        {
                            list.Add(index);
                        }
                    }
                }
            }

            if (CreateUrl != null)
            {
                try
                {
                    // This is an external method. Trap for exceptions and
                    // use default behavior if there is a failure.
                    return(CreateUrl(list));
                }
                catch (Exception ex)
                {
                    EventLog.Debug(ex);
                    EventLog.Warn("Exception calling CreateUrl method '{0}' with list '{1}'.",
                                  CreateUrl.ToString(),
                                  String.Join(", ", list));
                }
            }

            return(String.Format("{0}?{1}",
                                 absoluteUrl,
                                 String.Join("&", list.ToArray())));
        }