Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an 'unknown' parameter is supplied in a Request's Query String? [duplicate]

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.

like image 880
Manu Avatar asked Oct 19 '22 04:10

Manu


1 Answers

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));
like image 65
Rob Avatar answered Nov 01 '22 09:11

Rob