0

So I have this code where it gets data from parameter provided by a .ashx file but It always returns "" whenever executed although it has parameter in it.

URL I'm working with looks like

http://localhost:21614/AlbumManager.aspx?mp3=AudioHandler.ashx?ID=ACHI-0001

and the code used to get the ID inside the .ashx file looks like

public void ProcessRequest (HttpContext context) {
    string ID = context.Request.QueryString["ID"];
}

Is there anything I missed in order to get the parameter?

APPEND: 01/01/2018 (10:50 UTC+0) So the problem here is that I use this site as a reference for my codes and I tweaked it a little bit so it reads the the ID as a string (which is the datatype used in my SQL) but it never returns the parameter provided in the URL.

I also realized that when I hover the .QueryString from the code it stores {Id=} even when I changed the Id to data or such

MEGAtive
  • 3
  • 3

1 Answers1

1

ASP.NET expects individual parameters in querystring to be separated by & characters. ? is only used to separate querystring from preceding part of the URL. See How to pass multiple parameters in a querystring.

So URL should be:

http://localhost:21614/AlbumManager.aspx?mp3=AudioHandler.ashx&ID=ACHI-0001
Ňuf
  • 6,027
  • 2
  • 23
  • 26
  • Still not working. It still passes blank string. I use codes from [this site](https://www.aspsnippets.com/Articles/Save-MP3-Audio-Files-to-database-and-display-in-ASPNet-GridView-with-Play-and-Download-option.aspx) and tweaked it a little bit so it matches the database ID type (which is a string to begin with) but when I debug it, it doesn't get the ID. – MEGAtive Jan 01 '18 at 10:49
  • After you updated you question with more details, I realized that you probably do not read `ID` parameter directly from provided URL, but first you redirect to URL in `mp3` parameter (*AudioHandler.ashx?ID=ACHI-0001*) and then you read `ID` in *AudioHandler.ashx*. Is this assumption correct? In that case using `?` just before `ID` is correct (as it doesn't denote start of `ID` parameter, but is continuation of `mp3` param.) and my answer is wrong. Can you also provide content of `context.Request.Url.AbsoluteUri`? It seems problem is not in reading parameter, but in code you didn't provide. – Ňuf Jan 01 '18 at 14:13
  • Yea, I try to use the .ashx as a container for the mp3. And the content of the AbsoluteURI is `http://localhost:21614/AudioHandler.ashx?Id=` . – MEGAtive Jan 01 '18 at 15:31
  • @MEGAtive: Because there is no value of `Id` parameter, `context.Request.QueryString["ID"]` returns (correctly) empty string. Therefore problem is not in reading parameter from querystring, but instead problem is likely in the code that generates that URL. Unfortunatelly you question doesn't provide any information about this problematic part of your code, so nobody will probably be able to help you, until you provide all relevant information. – Ňuf Jan 06 '18 at 14:55