Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QueryString checking

Tags:

c#

asp.net

How to check if the web page contains any string queries at the page load?

like image 977
MAC Avatar asked Jul 17 '09 06:07

MAC


People also ask

How do you validate a QueryString?

Query string values can be checked using regular expressions. You can select regular expressions from the global White list or enter them manually. For example, if you know that a query string must have a value of ABCD , a regular expression of ^ABCD$ is an exact match test.

What is a QueryString used for?

A querystring is a set of characters input to a computer or Web browser and sent to a query program to recover specific information from a database .

What is QueryString in API?

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.

Is QueryString safe?

Yes. The entire text of an HTTPS session is secured by SSL. That includes the query and the headers.


1 Answers

You can determine if there are any values in the QueryString by checking its count:

Request.QueryString.Count > 0;

That said if you are trying to prevent a page from erroring because you don't want to access a value that is not there I recommend wrapping query parms up in page properties and returning safe values from the property.

As an example

// setting this as protected makes it available in markup
protected string TaskName
{
    get { return (string)Request.QueryString["VarName"] ?? String.Empty; }
}
like image 127
ahsteele Avatar answered Oct 17 '22 08:10

ahsteele