Can someone tell me what I can achieve the code given below: Check that what is the query The parameter 'return_path' and / or 'user_state' are located in the query string, and if so, add them to the redirect string in the query string.
As I am not a .NET dev and I do not have any servers, test it, I was hoping someone could give me some feedback.
ArrayList vars = new ArrayList (); Vars.Add ("return_path"); Vars.Add ("USER_STATE"); New url = "/ new / request / yuri" + "?"; ArrayList params = new arrelist (); Foreach (string key in the request .stringString) {if (vars.contains (key)) {params.Add (key + "=" + HttpUtility.URLPathEncode (Request.QueryString [key]); }} String [] paramArr = (string []) params.ToArray (typeof (string)); String query string = string.joint ("& amp;", paramaster); Response.Redirect (NEWURL);
thanks :)
It looks like what You must My only concern is the use of raw underscores (_) in a URL is not sure that url encoding is allowed. If this is a problem, then use the hyphen / loan or URL to encode the underscore character.
Added after the first response :
OK checked. Underscore is bad for host names, not URL parameters
Here the code has been revamped with genetics and LINQ. Probably there are more concise syntax present. Remember that the list still only runs once again, so it should be right.
list & lt; String & gt; VarNames = New list & lt; String & gt; {"Return_path", "user_state"}; Var args = this.Request.QueryString.AllKeys Where (key => varNames.Contains (key)). Select (key => key + "=" + HttpUtility.UrlEncode (Request .JQueryString [Key])); New url = "/ new / request / yuri"; If (args. Any ()) {newUrl + = "?" + String .joint ("& amp;", args); } reaction. Redirect (New URL);
Also keep in mind:
- The name of the HTML path is not the "path",
- The?
- If any of the parameter names are shown twice or more, then you do not get a list of prices only one value
- Response.Redirect Client Redirection, so it returns to the client Goes, which is directed to the new URL
- Response. Threading throws expansion to clean the redirect work process (which prevents any subsequent code from executing and although you can try / hold / end this special exception type automatically not retrieve again It does not matter what you do to handle it.
Comments
Post a Comment