0

I have a URL like so: www.domain.com/thispage.asp?param1&param2=test&param3=airplanes

A couple questions:

  1. Expectedly, I cannot access Request.QueryString("param1"), but I also cannot access any null keys. How do I get this value? The URI can't change unfortunately.

  2. When I iterate through the parameters for the keys, it shows I only have two: param1&param2 and param3. It's like the ampersand does not distinguish between parameters and so it sees that as one key. How can I get the values of the first two parameters? I don't want to use regex if I don't have to.

For the third parameter in this example, Request.QueryString("param3") works as it should.

Many thanks in advance.

Edit: My question is different, I've read the other post linked and like I stated above, I can't access a null key. Also, I have to use parenthesis to access the keys, not brackets. We are not using c#, so apologies if I tagged this incorrectly (I frankly don't know all the differences). Also, as stated, we cannot change the URI by adding a "=" or anything else - it will have multiple parameters, with one being just a plain value (or key, whatever it's called in this case).

One more thing I should add: When the URL is simply www.domain.com/thispage.asp?param1, then Request.QueryString is equal to "param1"

user256430
  • 3,575
  • 5
  • 33
  • 33
  • The URI would need to be `param1=&`, I think. Or just omit param1 from the request entirely if it isn't populated. – ADyson Jul 22 '19 at 23:14
  • 1
    P.S. you talk about a URL with `.asp` extension, usually indicating ASP Classic, but then tagged the question with ASP.NET. They are very different beasts. Which one are you really using here? – ADyson Jul 22 '19 at 23:17
  • 1
    @ElasticCode only if it really is ASP.NET ...see my comment above. Although ASP Classic may well behave in a similar way, I wouldn't be surprised. – ADyson Jul 22 '19 at 23:20
  • The second answer from ElasticCodes link really looks promising – grek40 Jul 23 '19 at 05:10
  • Can you elaborate on *"but I also cannot access any null keys"*? – grek40 Jul 23 '19 at 05:12
  • @grek40 Sure. When I try to access `Response.QueryString(null)` I get a 500 error. Likewise when I try and use `GetValues` or anything else with regards to the `null` key. – user256430 Jul 23 '19 at 16:24
  • @DondeEstaMiCulo you may want to access `Request`, not `Response`. Please clarify whether this was an error in your comment or in your code. – grek40 Jul 24 '19 at 05:17
  • You should be able to get the full querystring value using `Request.QueryString` then parsing the return string *(which will be `param1&param2=test&param3=airplanes`)* manually *(`Split()` on the `&` to get each key value pair)*. @grek40 Let's be clear the suggested duplicate is not helpful as they are solutions for ASP.Net **not** Classic ASP. – user692942 Jul 24 '19 at 06:23
  • I've just tested this and `Response.Write(Request.QueryString("Param1"))` does not return an error, but obviously, it doesn't write anything to the screen either because the querystring parameter is `Empty`. Not sure you're telling us the whole story here, what is the actual error? – user692942 Jul 24 '19 at 07:28
  • @grek40 My bad, I meant Request. That was indeed an error on my part @Lankymart Yes, I could use something like `instr()` or `split()` to achieve what I need. `Request.QueryString("Param1")` does not exist because it sees `param1&param2` as the key - apparently the ampersand does not separate the keys. – user256430 Aug 07 '19 at 14:30

0 Answers0