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); }
public static void RedirectToPage(string destinationPg, HttpContext context, NameValueCollection qsVals) { 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 redirectUrl = PageRedirect.GetUrlPefix(destinationPg); System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (qsVals != null) { for (int i = 0; i < qsVals.Count; i++) { sb.AppendFormat("&{0}={1}", context.Server.UrlEncode(qsVals.Keys[i]), context.Server.UrlEncode(qsVals[i])); } } redirectUrl += "?ReturnUrl=" + PageRedirect.GetCurrentPageEncoded(context) + sb.ToString(); context.Response.Redirect(redirectUrl, true); }
public static void SendBackToCallingPage(HttpContext context, NameValueCollection additionalParams, params string[] includedParams) { if (string.IsNullOrEmpty(context.Request.QueryString["ReturnURL"])) { throw new ArgumentException("To use this method, the requesting querystring must contain a value called 'ReturnURL'.", "context"); } PageRedirect.SendBackToCallingPage(context.Request.QueryString["ReturnURL"], context, additionalParams, includedParams); }
public static void SendBackToCallingPage(string destinationPg, HttpContext context, NameValueCollection additionalParams, params string[] includedParams) { 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."); } if (string.IsNullOrEmpty(destinationPg)) { throw new ArgumentNullException("desinationPg", "You must specify the destination page you want to redirect to."); } string responseUrl = PageRedirect.GetUrlPefix(destinationPg); System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (includedParams.Length > 0) { // We're using a delegate to define an 'anonymous' method, since the Array.ConvertAll // requires that we create a 'Converter' delegate pointed to a method, but this // saves the overhead of having a 'real' method call for one line of code. string[] lVals = Array.ConvertAll <string, string>(includedParams, new Converter <string, string>(delegate(string val) { return(val.ToLower()); })); HttpRequest req = context.Request; for (int i = 0; i < req.QueryString.Count; i++) { if (lVals.Contains(req.QueryString.GetKey(i).ToLower())) { sb.AppendFormat("&{0}={1}", context.Server.UrlEncode(req.QueryString.GetKey(i)), context.Server.UrlEncode(req.QueryString.Get(i))); } } } if (additionalParams != null) { for (int i = 0; i < additionalParams.Count; i++) { sb.AppendFormat("&{0}={1}", context.Server.UrlEncode(additionalParams.GetKey(i)), context.Server.UrlEncode(additionalParams[i])); } } string qs = sb.ToString(); if (!string.IsNullOrEmpty(qs)) { responseUrl += "?" + qs.TrimStart('&'); } context.Response.Redirect(responseUrl); }
public static void ClearQueryString(HttpContext context, string queryStringValues) { NameValueCollection nvCol = new NameValueCollection(); string[] pairs = queryStringValues.Split('|', ',', ' ', ';', '&'); for (int i = 0; i < pairs.Length; i++) { string[] val = pairs[i].Split('='); if (val.Length < 2) { throw new ArgumentException("Specified query string values is not in an allowable format."); } nvCol.Add(val[0], val[1]); } PageRedirect.ClearQueryString(context, nvCol); }
/// <summary> /// Performs a redirect to the previously specified page target, including the stored QueryString parameters. /// </summary> public void Go() { if (this._curMode == Mode.Redirect) { PageRedirect.RedirectToPage(this._dest, this._context, this._qsVals); } else if (this._curMode == Mode.ReturnToCallingPage) { if (string.IsNullOrEmpty(this._dest)) { if (this._includeQsNames.Count > 0) { PageRedirect.SendBackToCallingPage(this._context, this._qsVals, this._includeQsNames.ToArray()); } else { PageRedirect.SendBackToCallingPage(this._context, this._qsVals, this._includeQs); } } else { if (this._includeQsNames.Count > 0) { PageRedirect.SendBackToCallingPage(this._dest, this._context, this._qsVals, this._includeQsNames.ToArray()); } else { PageRedirect.SendBackToCallingPage(this._dest, this._context, this._qsVals, this._includeQs); } } } else { // Only way this can happen is if somebody messes with the code and // doesn't update this method. I like to be thorough... throw new InvalidOperationException("Redirect mode is not valid."); } }
private static string GetCurrentPageEncoded(HttpContext context) { return(context.Server.UrlEncode(PageRedirect.GetCurrentPage(context))); }
public static void ClearQueryString(HttpContext context) { PageRedirect.ClearQueryString(context, string.Empty); }
public static void SendBackToCallingPage(string destinationPg, HttpContext context, params string[] includedParams) { PageRedirect.SendBackToCallingPage(destinationPg, context, null, includedParams); }
public static void SendBackToCallingPage(string destinationPg, HttpContext context, NameValueCollection additionalParams, bool includeQueryString) { PageRedirect.SendBackToCallingPage(destinationPg, context, additionalParams, PageRedirect.GetQueryStringParamKeys(context.Request)); }
public static void SendBackToCallingPage(string destinationPg, HttpContext context, bool includeQueryString) { PageRedirect.SendBackToCallingPage(destinationPg, context, null, includeQueryString); }
public static void SendBackToCallingPage(HttpContext context, params string[] includedParams) { PageRedirect.SendBackToCallingPage(context, null, includedParams); }
public static void SendBackToCallingPage(HttpContext context, bool includeQueryString) { PageRedirect.SendBackToCallingPage(context, null, includeQueryString); }
public static void SendBackToCallingPage(HttpContext context) { PageRedirect.SendBackToCallingPage(context, true); }
//*************************************************************************** // Static Methods // public static void RedirectToPage(string destination, HttpContext context) { PageRedirect.RedirectToPage(destination, context, null); }