views:

43

answers:

2

Hello,

I have the following method:

public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl)

The value of the fullUrl is:

http://localhost:50435/page/view.aspx?si=00&us=admin&ut=smt&

When I do:

NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);

I get:

{http%3a%2f%2flocalhost%3a50435%2fpage%2fview.aspx%3fsi=00&us=admin&ut=smt&}

But I need to obtain the parameters in the QueryString of this page, and with this value, I cannot obtain the "si" value, because the question mark, that starts the querystring is encoded. So I thought: "humm... I should try to do the HttpUtility.HtmlEncode()"

However the method HtmlEncode returns void: However the second parameter of this method sends the value to a TextWriter. But it isn't the NameValueCollection.

Maybe the solution is simple... but I cannot see it.

+1  A: 

You need to trim it down to just the querystring before parsing, like this:

if (fullUrl.Contains("?")) {
  fullUrl = fullUrl.Substring(fullUrl.IndexOf("?") + 1);
}
NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);
Nick Craver
+1  A: 

You could try:

var si = Request["si"];
var user = Request["us"];
//etc.
Robert
You mean `Request.QueryString["si"]`.
Mehrdad Afshari
I meant: Request["xy"], I changed this.
Robert