In ASP.NET, I build a string redirectURL
to redirect to ADFS
form with multiple query string parameters. One such complex parameter is the returnURL
with multiple parameters.
My problem is that only the first parameter of the returnURL
is available when it actually return.
E.g. redirectURL = <br>
https://aaa.aaa/adfs/Form.aspx <br>
?DomainName=domain <br>
&AccountName=account <br>
&returnURL=https://bbb.bbb/MyPage.aspx?param1=111¶m2=222
I know it complicates when identify the & symbol
of actual parameters and parameters in returnURL
. Please help me to fix this.
Thanks in advance.
Passing Multiple Parameters for QueryString To pass multiple parameters, we will use “&” symbol to separate the other field and value combinations. On button click (from code behind), redirect to another page with two QueryString parameters. Now this example has two parameters or variables.
Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
To add a parameter to the URL, add a /#/? to the end, followed by the parameter name, an equal sign (=), and the value of the parameter. You can add multiple parameters by including an ampersand (&) between each one.
Note: To pass more than one parameter within the query string url, we need to use & (ampersand) to separate the parameters. Check below for the complete example. For this tutorial, I created two pages, Page1. aspx is used to redirect the user to another page with a query string and another page is Page2.
You should use HttpUtility.UrlEncode when composing the link and HttpUtility.UrlDecode when resolving it.
For your case it should be something similar to:
"https://aaa.aaa/adfs/Form.aspx?DomainName=domain&AccountName=account&returnURL=" +
HttpUtility.UrlEncode("https://bbb.bbb/MyPage.aspx?param1=111¶m2=222")
And then at the target use:
HttpUtility.UrlDecode(Request.QueryString["returnURL"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With