0

This is my ASHX File where I am catching multiple parameters from request URL using httpcontext, and it is working properly but when I am including a Hash(#) value in Text parameter through the URL. It is not taking the value of FLOW which is another parameter(next to Text parameter).

So it is working for:

http://localhost:10326/ussd.ashx?user=MSL&pass=MSL663055&tid=65506&msisdn=8801520101525&text=***3333**&flow=begin&momt=mo

And it is not working for:

http://localhost:10326/ussd.ashx?user=MSL&pass=MSL663055&tid=65506&msisdn=8801520101525&text=***3333#**&flow=begin&momt=mo

My ASHX files:

public void ProcessRequest(HttpContext context)
{
    HttpRequest httpRequest = context.Request;
    string user = httpRequest.QueryString["user"].ToString();
    string pass = httpRequest.QueryString["pass"].ToString();
    string tid = httpRequest.QueryString["tid"].ToString();
    string msisdn = httpRequest.QueryString["msisdn"].ToString();
    string text = httpRequest.QueryString["text"].ToString();
    flow = httpRequest.QueryString["flow"].ToString();
    HttpContext.Current.Session["user"] = user;
    HttpContext.Current.Session["pass"] = pass;
    HttpContext.Current.Session["tid"] = tid;
    HttpContext.Current.Session["msisdn"] = msisdn;
    HttpContext.Current.Session["text"] = text;
    HttpContext.Current.Session["flow"] = flow;
Adrian Sanguineti
  • 2,455
  • 1
  • 27
  • 29

1 Answers1

2

You need to URI encode your parameter values before they are added to the URL. This way the server will not get confused by unsafe characters such as '#' which has its own meaning when included as part of a URL. See RFC 3986 Section 2.

See Encode URL in JavaScript as an example of how to encode the sent data using JavaScript. Whatever is sending the data in the URL will need to do the encoding. There is not much you can do once the request has reached the server. Without knowing how your URL is being created, I can't offer much more.

In short: the problem is with your client code not your ASHX file.

Community
  • 1
  • 1
Adrian Sanguineti
  • 2,455
  • 1
  • 27
  • 29
  • 1
    correct, Functions for url encoding are .Net : `Httputility.UrlEncode()` , Javascript : `encodeURI()` or `encodeURIComponent()` – par Oct 26 '16 at 08:33
  • Section 3 even has a nice [ASCII graph](https://tools.ietf.org/html/rfc3986#section-3) that shows the URI parts, including the fragment – Panagiotis Kanavos Oct 26 '16 at 08:54