Asp net validating querystring

Posted by / 21-Feb-2021 04:35

At the same time, if you need more logic than a simple regular expression then you probably also need to access a database, and probably your logic may be quite sophisticated.My rule of thumb is go with a route constraint if you just want to rule out a URL pattern and have multiple patterns to take into account; accept the request and validate within the controller elsewhere.It happened by pure coincidence, but it took me a few minutes to find it out.

You register a route constraint class as below: With this trick switched on, a URL that has an invalid parameter just doesn’t match up the route. What do you really need to do when you get a valid URL pattern but an invalid parameter?

There might be applications where a constraint that fails just identifies an invalid URL that can be served better by another route down the list.

Likewise, there might be applications that need to stop the search for a valid route and just handle the validation and related view internally.

Once in a controller, you have no limits on what you can do; and you also have the chance to adjust the error view more comfortably.

So my idea was to grab the parameter on a given action method, validate it and then decide what to do next.

asp net validating querystring-50asp net validating querystring-70asp net validating querystring-23