My requirement is to parse Http Urls and call functions accordingly. In my current implementation, I am using nested if-else statement which i think is not an optimized way.
This might come as a bit of a late answer but I found myself recently trying to parse some URLs and I went along using a combination of Uri
and System.Web.HttpUtility
as seen here, my URLs were like http://one-domain.com/some/segments/{param1}?param2=x....
so this is what I did:
var uri = new Uri(myUrl);
string param1 = uri.Segments.Last();
var parameters = HttpUtility.ParseQueryString(uri.Query);
string param2 = parameters["param2"];
note that in both cases you'll be working with string
s, and be specially weary when working with segments.