1

Url: http://localhost:3000/Login/SignIn?timeout=5000&returnUrl=/Home.ashx?param1=555&param2=666

Output:

{
    [0]: { timeout, 3000 },
    [1]: { param1, 555 },
    [2]: { param2, 666 }
}
3
  • 3
    that uri seems malformed; the /, ?, =, & etc tokens in the returnUrl should have been url-encoded, surely? i.e. ...&returnUrl=%2FHome.ashx%3Fparam1%3D555%26param2%3D666 ? then the timeout is a simple decode, but you'd need to re-parse the value of returnUrl and extract those inner parameter values Commented Oct 6, 2022 at 12:57
  • It makes no sense to both use individually unique names for your values and keep all values in isolated objects. This isn't a question, it's an implicit expectation to finish/correct a half-baked idea. Commented Oct 6, 2022 at 13:08
  • 1
    Does this answer your question? Can't get query parameter from HttpRequestData Commented Oct 6, 2022 at 13:09

1 Answer 1

1

I'm assuming that the returnUrl here is incorrectly encoded, and in the real code would be url-encoded; in that case, you need a second pass to parse the return-url parameters, but - something like:

var uri = new Uri("http://localhost:3000/Login/SignIn?timeout=5000&returnUrl=%2FHome.ashx%3Fparam1%3D555%26param2%3D666");
var query = HttpUtility.ParseQueryString(uri.Query);
foreach (string key in query.Keys)
{
    Console.WriteLine($"{key}={query[key]}");
}
// further-decode returnUrl values
uri = new Uri(uri, query["returnUrl"]);
query = HttpUtility.ParseQueryString(uri.Query);
foreach (string key in query.Keys)
{
    Console.WriteLine($"{key}={query[key]}");
}

which outputs:

timeout=5000
returnUrl=/Home.ashx?param1=555&param2=666
param1=555
param2=666
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.