说我目前的页面url已经得到(http://mysite/english/faq.aspx?faqid = 12123 & cid = 4545 & intcid = 65456 & H =人)如何从c#2.0中删除当前网页查询字符串的查询字符串的特殊列表
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
我很困惑如何得到这个,其实我想打一个函数,它会做这一切。
请建议!!
编辑:
我申请新代码来解决上述问题,但得到的小卡,而转换的NameValueCollection再次查询字符串。
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(); //Here I am not able to convert back to querystring, however there are other ways to get it like (http://leekelleher.com/2008/06/06/how-to-convert-namevaluecollection-to-a-query-string/), is there any other way to do that
}
}
return retQueryString;
}
我不会删除直接查询字符串,首先我会检查当前页面的网址是否已经有任何查询字符串,如果是我会检查查询字符串中是否包含我的排除列表中,如果任何查询字符串拿到赛我的名单,然后我将删除从我的整个查询字符串列表中,进一步我会将该查询字符串传递给我的xslt进一步用法,有关这方面的任何想法我们如何能做到这一点 –
它的好,现在你只要把条件如你所愿(/ /你的条件)这样...没有人为你写代码。试试你的东西! – Ahsan
是否有任何微软内置功能,我们可以匹配一个数组与其他没有两个循环 –