Marek
Marek

Reputation: 372

HttpUtility.ParseQueryString weird behaviour

Can you someone please explain me this behaviour of ParseQueryString:

var qs = HttpUtility.ParseQueryString("/Site/controller/Index?date=now");
var obj = qs["date"]; //qs["date"] is   null

Why qs["date"] is null? What do I miss?

Thank you.

Upvotes: 1

Views: 677

Answers (2)

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

As you probably know, ParseQueryString expects just the query string part of a URL, If you have the URL you can use this code:

Uri myUri = new Uri("http://www.example.com/Site/controller/Index?date=now");
string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("date");

Upvotes: 9

Tushar Gupta
Tushar Gupta

Reputation: 15923

You need to pass onlly the query string not the whole URL:

 var qs = HttpUtility.ParseQueryString("date=now");

Upvotes: 1

Related Questions