0

In my Asp.net (C#) application, I need to read three parameters from the query string (Item, Code and Location). Url is given below.

http://localhost/Reports?ITEM=A#1234&CODE=0013&LOCATION=LOCA#001

I am reading it like this.

            _code = Request["CODE"]; //value should be 0013
            _item = Request["ITEM"]; //value should be A#1234
            _location = Request["LOCATION"]; //value should be LOCA#001

But after # character, nothing retrievable to the variables. Our database contains lots of data items with hash(#) character. Any idea how to read with # ?

Hasta Tamang
  • 2,205
  • 1
  • 18
  • 17
Anura Adhikari
  • 305
  • 1
  • 10
  • Try using encodeURIComponent Refer to this thread: https://stackoverflow.com/questions/2828211/how-to-include-special-characters-in-query-strings – BizApps Mar 23 '19 at 05:29

1 Answers1

1

Use URL encoding for the param values urlencode

To encode or decode values outside of a web application, use the WebUtility class.

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));

        }
    }
NMK
  • 1,010
  • 10
  • 18