Exemplo n.º 1
0
        public static void ClearQueryString(HttpContext context, NameValueCollection newParams)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", "You must pass the current HttpContext object for this method to function.");
            }
            else if (context.Response == null || context.Request == null)
            {
                throw new Exception("Specified HttpContext must contain both a valid request and response object.");
            }

            string responseUrl = PageRedirect.GetCurrentPage(context);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (newParams != null)
            {
                for (int i = 0; i < newParams.Count; i++)
                {
                    sb.AppendFormat("&{0}={1}", context.Server.UrlEncode(newParams.Keys[i]), context.Server.UrlEncode(newParams[i]));
                }
                responseUrl += "?" + sb.ToString().TrimStart('&');
            }

            context.Response.Redirect(responseUrl);
        }
Exemplo n.º 2
0
 private static string GetCurrentPageEncoded(HttpContext context)
 {
     return(context.Server.UrlEncode(PageRedirect.GetCurrentPage(context)));
 }