[英]URL # issuie c# querystring asp.net
我正在嘗試使用以下內容來整理我的查詢字符串。 地址中需要顯示一個井號,例如:
Blk 344,Jurong West,Street 11,#02-111
哪個存儲在變量address
。 我正在嘗試使用此代碼替換哈希符號: address.Replace("#","%23")
string url = "thankyou.aspx?firstname=" + firstname + "&" +
"lastname=" + lastname + "&" + "address=" + address.Replace("#","%23")+
"&" + "total=" + total + "&" + "nric=" + tbID.Text + "&" + "country=" +
ddlCountry.SelectedValue + "&" + "orderid=" + orderid + "&"+
"postalcode="+tbPostalCode.Text;
但是它仍然拋出錯誤。 當我將其替換為查詢字符串時,它很好並且數據顯示也很好,所以這不是問題。
使用Uri.EscapeDataString編碼所有查詢參數值:
string url = "thankyou.aspx?firstname=" + Uri.EscapeDataString(firstname)
+ "&lastname=" + Uri.EscapeDataString(lastname)
+ "&address=" + Uri.EscapeDataString(address)
+ "&total=" + Uri.EscapeDataString(total)
+ "&nric=" + Uri.EscapeDataString(tbID.Text)
+ "&country=" + Uri.EscapeDataString(ddlCountry.SelectedValue)
+ "&orderid=" + Uri.EscapeDataString(orderid)
+ "&postalcode=" + Uri.EscapeDataString(tbPostalCode.Text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.