Note that there are some explanatory texts on larger screens.

plurals
  1. POWhats the quickest way to dedupe a querystring in C# (ASP.net)
    primarykey
    data
    text
    <p>I have an issue whereby the company uses a business tracking system that captures a users first visit and redirects them to the page they were trying to visit but with a refferer URL attached... Now as the referer URL carries the url that the person was trying to visit (dont ask why, Ive no idea) it causes me to have a duplicate of every value.</p> <p>So visiting this...</p> <p><strong>home.aspx?test=test&amp;test2=test2</strong></p> <p>becomes </p> <p><strong>home.aspx?test=test&amp;test2=test2&amp;referrerurl=home.aspx?test=test&amp;test2=test2</strong></p> <p>Now, URL Encoding the referrer would sort the issue but i've more chance of being molested by a gorilla; so the question stands. How do I dedupe the output from .QueryString ?</p> <p>Currently I'm using this ...</p> <pre><code>private string queryClean(string entity) { try { if(Request.QueryString["referrerUrl"] != null){ string[] Split = entity.Split(new Char[] { ',' }); string tmpValue = Convert.ToString(Split[0]); return tmpValue; }else{ return entity; } } catch (Exception cleanError) { errors.Text += "-clean-" + cleanError + "-endclean-"; return entity; } } </code></pre> <p>(ignore the try/catch we have app level error catching, but I'm still playing with it).</p> <p>I'm using C# .net 2</p> <p>Thanks</p> <hr> <p>[Additional Info]</p> <p>The reffererURL will always be on the end of the string so it could be possible to delete all of the query string after this point?</p> <p>I've tried using </p> <pre><code>string test = Convert.ToString(Request.QueryString); string[] tRSplit = Regex.Split(test, "&amp;referrerUrl"); Response.Write(tRSplit[0]); </code></pre> <p>and...</p> <pre><code>System.Collections.Generic.List&lt;string&gt; testb = new System.Collections.Generic.List&lt;string&gt;(Convert.ToString(Request.QueryString).Split('&amp;')); for (int i = 0; i &lt; testb.Count; i++) { Response.Write(i +": "+ testb[i].ToString()+"&lt;br&gt;&lt;br&gt;"); } </code></pre> <p>Both still produce the duplicates </p> <hr> <p>I could use <a href="http://www.developerfusion.com/code/4398/string-manipulation-in-c/" rel="nofollow noreferrer">Trim</a> But is there a cleaner/faster way of achieving this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload