說我目前的頁面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
是否有任何微軟內置功能,我們可以匹配一個數組與其他沒有兩個循環 –