使用c#获取查询字符串值
本文关键字:字符串 查询 获取 使用 | 更新日期: 2023-09-27 18:13:58
我使用下面的代码通过javascript分配iframe src。它工作得很好。但是在c#代码后面,我得到了这样的查询字符串。id=Y&%3bcust_id=100&%3
。我怎样才能减少这个。现在
var value = "validity.aspx?id=Y&cust_id=" + cust_id + "";
frameElement.src = value
我想从查询字符串中获取客户的值,但它总是返回null。
if(Request.QueryString["cust_id"] !=null) //It returns null
您需要对"&"字符进行编码。由于某种原因,服务器将它们读取为&3b.
试试这个:
var value = "validity.aspx?id=Y&cust_id=" + cust_id + "";
value = encodeURIComponent(value);
frameElement.src = value
您需要使用HttpUtility解码URL。HtmlDecode
试试这样写:
var value = HttpUtility.HtmlDecode(URL);