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

user1408470 picture user1408470 · Jan 12, 2013 · Viewed 44.6k times · Source

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.

Answer

Adam Tal picture Adam Tal · Jan 12, 2013

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