tags:

views:

31

answers:

1

Hi all,

Could someone tell me if the code below would achieve what I want, which is: Check if the query parameters 'return_path' and/or 'user_state' are present in the query string, and if so append them to the query string of the redirect URI.

As I'm not a .NET dev and don't have a server to test this on, I was hoping someone could give me some feedback.

ArrayList vars = new ArrayList();
vars.Add("return_path");
vars.Add("user_state");

string newUrl = "/new/request/uri" + "?";
ArrayList params = new ArrayList();
foreach ( string key in Request.QueryString ) {
    if (vars.contains(key)) {
        params.Add(key + "=" + HttpUtility.URLPathEncode(Request.QueryString[key]));
    }
}
String[] paramArr = (String[]) params.ToArray( typeof (string) );
String queryString = String.join("&", paramArr);

Response.Redirect(newUrl);

Thank you :)

A: 
Swanny
Thanks you :) I just need to hear from someone who has some actual experience with .NET.I've never had problems with underscores in query strings before. But is there something in particular with .NET I should be aware of?
kasper pedersen
Updated response. Hopefully some more info there. Did spot one method naming issue.
Swanny
Wow, thank you for the very comprehensive answer :)
kasper pedersen