views:

311

answers:

1

My previous question is urlrewriter problem: Query string is duplicated shown?

I'm developing asp.net web site. But has a one problem. There is duplicated query string like this www.domainname.com/default.aspx?Query=Value1&Query=Value2 I'm using to too many pages like this Request.QueryString["Query"]. But this return Value1,Value2 . I don't want to fix this problem to too many pages. I want to fix querystring before pageload. I think that Maybe will write some function on global.asax. But i don't know to how write it.

You have a any idea?

A: 

I beleive Request.QueryString itself is read-only. You could setup your own collection containing whatever you want to use:

public Dictionary<string, object> qsValues = new Dictionary<string, object>();

foreach (string key in Request.QueryString.Keys) {
    if (Request.QueryString[key].Count > 1) {
        qsValues[key] = Request.QueryString[key][0];
    }
    else {
        qsValues[key] = Request.QueryString[key];
    }
}

Or just access the first entry in the list of values for that query string parameter in your code:

if (Request.QueryString["Query"].Count > 1) {
    queryValue = Request.QueryString[0];
}
Jez