Hi,
Firstly, you might want to URL-encode the value of your RedirectUrl
parameter, some characters aren't allowed in the querystring, including
question marks. For more info about URL encoding and the
HttpUtility.HtmlEncode(String) function, see MSDN:
http://msdn2.microsoft.com/en-us/library/73z22y6h(VS.80).aspx
Once you've got the encoded value of RedirectUrl from the QueryString
collection, you might need to HtmlDecode() it to get back the original
values:
http://msdn2.microsoft.com/en-us/library/system.web.httputility.htmldecode(VS.80).aspx
Next, you need to get the querystring from you URL value. The easiest
way would be to use string functions to get everything to the right of
the "?", but you wanted to avoid this. Therefore, another approach
would be to create a Uri object from your URL string:
http://msdn2.microsoft.com/en-US/library/system.uri(VS.80).aspx
Uri myUrl = new Uri("
http://www.server2.com?id=777");
You can now get the querystring part of the URL using the Uri.Query
property:
string myQuery = myUrl.Query;
Finally, how do you get the value of the id parameter without using
string functions? You can use the HttpUtility.ParseQueryString()
method to parse your querystring into a NameValueCollection object:
http://msdn2.microsoft.com/en-US/library/ms150046.aspx
NameValueCollection queryCol = HttpUtility.ParseQueryString(myQuery);
idValue = queryCol["id"];
Note that ParseQueryString() is only supported in .NET 2.0+.
Hope this helps,
Chris