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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:19:41  来源:igfitidea点击:

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

c#asp.netescapingquery-stringadfs

提问by user1408470

In ASP.NET, I build a string redirectURLto redirect to ADFSform with multiple query string parameters. One such complex parameter is the returnURLwith multiple parameters.

在 ASP.NET 中,我构建了一个字符串redirectURL以重定向到ADFS具有多个查询字符串参数的表单。一个这样的复杂参数是returnURL具有多个参数的。

My problem is that only the first parameter of the returnURLis 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&param2=222

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

我知道识别&amp 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&param2=222")

And then at the target use:

然后在目标使用:

HttpUtility.UrlDecode(Request.QueryString["returnURL"])