Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL with multiple parameters as a query string in ASP.NET

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&param2=222

I know it complicates when identify the &amp symbol of actual parameters and parameters in returnURL. Please help me to fix this.

Thanks in advance.

like image 886
user1408470 Avatar asked Jan 12 '13 14:01

user1408470


People also ask

How can pass multiple values in query string in asp net?

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.

How can URL have multiple query parameters?

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 "&".

How do I pass a URL with multiple parameters into a URL?

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.

How can pass multiple parameter in URL in asp net?

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.


1 Answers

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&param2=222")

And then at the target use:

HttpUtility.UrlDecode(Request.QueryString["returnURL"])
like image 68
Adam Tal Avatar answered Oct 15 '22 15:10

Adam Tal