user1408470
user1408470

Reputation: 1515

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.

Upvotes: 5

Views: 53120

Answers (1)

Adam Tal
Adam Tal

Reputation: 5961

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"])

Upvotes: 11

Related Questions