在我的Asp.net(C#)应用程序中,我需要从查询字符串中读取三个参数(项,代码和位置)。网址如下。
http://localhost/Reports?ITEM=A#1234&CODE=0013&LOCATION=LOCA#001
我正在这样阅读。
_code = Request["CODE"]; //value should be 0013
_item = Request["ITEM"]; //value should be A#1234
_location = Request["LOCATION"]; //value should be LOCA#001
但是在#
字符之后,没有任何可检索到的变量。
我们的数据库包含许多带有哈希(#)
字符的数据项。知道如何使用#
进行阅读吗?
答案 0 :(得分:1)
将URL编码用于参数值urlencode
要对Web应用程序外部的值进行编码或解码,请使用WebUtility类。
using System;
using System.Net;
public class Program
{
public static void Main()
{
string urlValue = "ITEM="+WebUtility.UrlEncode("A#1234") + "&CODE=0013&LOCATION=" + WebUtility.UrlEncode("LOCA#001");
Console.WriteLine(urlValue);
Console.WriteLine(WebUtility.UrlDecode(urlValue));
}
}