C# 带有多个参数的 URL 作为 ASP.NET 中的查询字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14294248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
URL with multiple parameters as a query string in ASP.NET
提问by user1408470
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.
在 ASP.NET 中,我构建了一个字符串redirectURL
以重定向到ADFS
具有多个查询字符串参数的表单。一个这样的复杂参数是returnURL
具有多个参数的。
My problem is that only the first parameter of the returnURL
is available when it actually return.
我的问题是returnURL
当它实际返回时只有第一个参数可用。
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.
我知道识别& symbol
实际参数和returnURL
. 请帮我解决这个问题。
Thanks in advance.
提前致谢。
采纳答案by Adam Tal
You should use HttpUtility.UrlEncodewhen composing the link and HttpUtility.UrlDecodewhen resolving it.
您应该使用HttpUtility.UrlEncode组成的链接,当HttpUtility.UrlDecode解决时。
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"])