Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 824517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:06:41+00:00 2026-05-15T03:06:41+00:00

Could someone tell me if the code below would achieve what I want, which

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:06:42+00:00Added an answer on May 15, 2026 at 3:06 am

    Looks like it will achieve what you want.
    My only concern is the use of the raw underscore (_) in a URL. Not sure that’s allowed for URL encoding. If it turns out to be an issue, use either hyphen/minus or URL encode the underscore character.

    Added after first response:

    Ok. Checked. The underscore is bad for host names, not URL params.

    Here is the code revamped with generics and LINQ. There’s probably more concise syntax out there. Remember the list still only gets iterated once so it should be just as quick.

    List<string> varNames = new List<string> { "return_path", "user_state" };
    
    var args = this.Request.QueryString.AllKeys
                    .Where( key => varNames.Contains( key) )
                    .Select( key => key + "=" + HttpUtility.UrlEncode(Request.QueryString[key]) );
    
    string newUrl = "/new/request/uri";
    if (args.Any())
    {
        newUrl += "?" + String.Join("&", args);
    }
    
    Response.Redirect(newUrl);
    

    Also note:

    • The Html Encode method does not have “Path” in the name,
    • the ? was being added in the original sample regardless of the params found
    • if either of the parameter names appear twice or more then you get a list of values not just one value
    • Response.Redirect is a client redirection so it goes back to the client which is directed to the new URL
    • Response.Redirect throws a ThreadingException to clean up the worker process (which stops any subsequent code from executing and though you can try/catch/finally this special exception type gets rethrown automatically not matter what you do to handle it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please tell me which objects types can be tested using Regular Expressions
Could someone please tell me what is wrong with this code? It works fine
Could someone tell me what the units the SetTimeout(int) method in the ICriteria interface
Could someone tell me why the SSRS web service ReportService2005.asmx has a recursive parameter
Could someone tell me how the field Task Group is used in standard SharePoint
I've recently written this with help from SO. Now could someone please tell me
Could someone tell me why this doesn't work? def selectAndCopy(x,y,z,w): ctypes.windll.user32.SetCursorPos(x,y) time.sleep(1) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,
I have a mystery object in Javascript - please could someone tell me how
Could someone maybe tell me what i'm doing wrong? I'm betting im missing one
Could someone maybe tell me what i'm doing wrong? I'm betting im missing one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.