troubleshooting Question

How to remove partucular list of querystring from current page url querystring in c#2.0

Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates asked on
C#
10 Comments1 Solution455 ViewsLast Modified:
hi Experts,
Say my current page url has got http://localhost:2345/english/faq.aspx?faqid=12123&cid=4545&intcid=65456&h=man
string excludeQuerystring = DynConfig.Item("GoogleSEOLinkSettings/ExcludeQuerystring"); //this is the list of my exclude querystring (cid,intcid,del)

querystring = HttpContext.Current.Request.Url.AbsoluteUri.Split('?')[1]; //I will get faqid=12123&cid=4545,intcid=65456

StringBuilder fullQueryString = new StringBuilder();

if (!string.IsNullOrEmpty(excludeQuerystring) && !string.IsNullOrEmpty(querystring))
{
	string[] strEQ = excludeQuerystring.Split(',');  //making a array of excluded querystrings

	NameValueCollection navValues = HttpUtility.ParseQueryString(querystring);  //getting the list of querystring in NameValueCollection

	if (navValues.Count > 0)
	{
		string[] strQ = navValues.AllKeys;
		if(strQ.Length>0)
		{
			
		}
	}
}	

querystring= ?+faqid=12123&h=man //here I want updated querystring which does not have any querystring which is there in my excludeQuerystring

I am confused how to get this, actually I want to make a function which will do this all.

Please suggest!!

EDIT:

I changed the code for above implementation. Please see the code.

 protected void Page_Load(object sender, EventArgs e)
        {
            string querystring = string.Empty;

            string excludeList = "cid,intcid,del";

            if (!string.IsNullOrEmpty(excludeList))
            {
                string getFinalString = GetQueryString(excludeList);
                getFinalString = "?" + getFinalString;
            }
        }

        public string GetQueryString(string excludeArray)
        {
            string retQueryString = string.Empty;
            if (excludeArray.IndexOf(",") != -1)
            {
                string[] strArray = excludeArray.Split(",".ToCharArray());
                NameValueCollection filtered = new NameValueCollection();

                filtered.Add(HttpUtility.ParseQueryString(Request.Url.Query));
                if (filtered.HasKeys())
                {
                    foreach (string strMatch in strArray)
                    {
                        filtered.Remove(strMatch);
                    }
                    retQueryString = filtered.ToString();
                }
            }

            return retQueryString;
        }

Now when I am going to convert back to querystring from NameValueCollection existing keys
retQueryString = filtered.ToString();
what code will be written for this as I am not able to convert it back to string.
ASKER CERTIFIED SOLUTION
Robert Schutt
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros