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.
So visiting this...
home.aspx?test=test&test2=test2
becomes
home.aspx?test=test&test2=test2&referrerurl=home.aspx?test=test&test2=test2
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 ?
Currently I'm using this ...
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;
}
}
(ignore the try/catch we have app level error catching, but I'm still playing with it).
I'm using C# .net 2
Thanks
[Additional Info]
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?
I've tried using
string test = Convert.ToString(Request.QueryString);
string[] tRSplit = Regex.Split(test, "&referrerUrl");
Response.Write(tRSplit[0]);
and...
System.Collections.Generic.List<string> testb = new System.Collections.Generic.List<string>(Convert.ToString(Request.QueryString).Split('&'));
for (int i = 0; i < testb.Count; i++)
{
Response.Write(i +": "+ testb[i].ToString()+"<br><br>");
}
Both still produce the duplicates
I could use Trim But is there a cleaner/faster way of achieving this.