5

For example, if a query string has 2 expected parameters , say. param1 = "abc" & param2 = "def".

I know that Request.QuerySring["abc"] will check for "abc" in query string.

But is there any way to validate if user enters anything else other than param1 or param2?

Thanks.

user2864740
  • 60,010
  • 15
  • 145
  • 220
Manu
  • 73
  • 7
  • Why do you care? if the user enters a value with an identifier that you don't use in your code, then it's meaningless anyway. – Zohar Peled Aug 26 '15 at 04:45
  • 8
    http://stackoverflow.com/questions/2375372/is-there-a-way-to-get-all-the-querystring-name-value-pairs-into-a-collection – JleruOHeP Aug 26 '15 at 04:46

2 Answers2

3

Yes, you can use AllKeys:

Request.QueryString.AllKeys

To get the list of parameters used apart from 'param1' and 'param2':

var expectedParams = new [] { "param1", "param2" };
var additionalParams = Request.QueryString.AllKeys.Where(k => !expectedParams.Contains(k));
Rob
  • 26,989
  • 16
  • 82
  • 98
0

If you try to retrieve Request.QuerySring["param1"] you will get the value abc. Now if the user change the KEYS of the query-string you will not able receive it as your are retrieving the query-string values by KEYS. So you dont need to validate users inputs.

rafat
  • 819
  • 2
  • 10
  • 25